#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair < int, int >

using namespace std;

ll mem[502][502];

int N, M;

ll value (int i, int j);

ll ask (int i, int j) {
//    assert(1 <= i && i <= N && 1 <= j && j <= M);
    if (mem[i][j])
        return mem[i][j];
    return mem[i][j] = value(i, j);
}

bool check (int i, int j) {
    bool ok = 1;
    assert(1 <= i && i <= N && 1 <= j && j <= M);

    if (i > 1)
        ok &= ask(i - 1, j) > ask(i, j);

    if (i + 1 <= N)
        ok &= ask(i + 1, j) > ask(i, j);

    if (j > 1)
        ok &= ask(i, j - 1) > ask(i, j);

    if (j + 1 <= M)
        ok &= ask(i, j + 1) > ask(i, j);
    return ok;
}

pii find_locmin_point (int n, int m) {
    N = n, M = m;
    for (int i = 1; i <= n; ++i) {
        int l = 1, r = m;
        while (l + 1 < r) {
            int mid = l + r >> 1;
            if (mid == 1) {
                l = mid;
                continue;
            }

            assert(1 < mid && mid <= m);
            if (ask(i, mid - 1) > ask(i, mid))
                l = mid;
            else
                r = mid - 1;
        }
        if (check(i, l))
            return {i, l};
        if (check(i, r))
            return {i, r};
    }
}

//      /
//\    /
// \  /
//  \/

//
//int main () {
//    ios_base::sync_with_stdio(0);
//    cin.tie(0);
//    int test = 1;
//    while (test--) {
////        slv();
//        cout << "\n";
//    }
//}
