#include<bits/stdc++.h>

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

using namespace std;

map < pii, ll > mem;

int N, M;

ll value (int i, int j);

ll ask (int i, int j) {
    if (mem.find({i, j}) != mem.end())
        return mem[{i, j}];
    return mem[{i, j}] = value(i, j);
}

bool check (int i, int j) {
    bool ok = 1;
    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 m = l + r >> 1;
            if (ask(i, m - 1) > ask(i, m))
                l = m;
            else
                r = m - 1;
        }
        if (check(i, l))
            return {i, l};
        if (r == m)
            return {i, r};
    }
}

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

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