#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 NN, MM;

ll value (int i, int j);

ll ask (int i, int j) {
//    assert(1 <= j && j <= MM);
//    assert(1 <= i && i <= NN);
    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 <= NN)
        ok &= ask(i + 1, j) > ask(i, j);

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

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

int find_row (int i) {
    int l = 1, r = MM;
    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 l;
    if (check(i, r))
        return r;
    return -1;
}

pii find_locmin_point (int N, int M) {
    NN = N, MM = M;
    for (int i = 1; i <= N; ++i) {
        int x = find_row(i);
        if (x != -1)
            return {i, x};
    }
}

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

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