#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdint>
#define int long long

//using namespace std;

    const char nl = '\n';

    #include<utility>

    long long value(int r, int c);

    long long p[505][505];

    long long get(int r, int c) {
        if (p[r][c]) {
            return p[r][c];
        } else {
            p[r][c] = value(r, c);
            return p[r][c];
        }
    }

    std::pair<int, int> find_locmin_point(int N, int M) {
        for (int i = 0; i <= N; i++) {
            for (int j = 0; j <= M; j++) {
                p[i][j] = 0;
            }
        }
        if (N == 1) {
            int i = 1;
            for (int b = 10; b >= 0; b--) {
                if (i + (1LL << b) <= M && get(1, i) > get(1, i + (1LL << b))) {
                    i += (1LL << b);
                }
                if (i - (1LL << b) >= 1 && get(1, i) > get(1, i - (1LL << b))) {
                    i -= (1LL << b);
                }
            }
            return {1, i};
        }
        int i = 1;
        int j = 1;
        bool f = 1;
        for (int b = 10; b >= 0; b--) {
            int c = (1LL << b);
            f = 0;
            if (i + c <= N) {
                if (get(i + c, j) < get(i, j)) {
                    i += c;
                    f = 1;
                    continue;
                }
            }

            if (j + c <= M) {
                if (get(i, j + c) < get(i, j)) {
                    j += c;
                    f = 1;
                    continue;
                }
            }

            if (i - c > 0) {
                if (get(i - c, j) < get(i, j)) {
                    i -= c;
                    f = 1;
                    continue;
                }
            }

            if (j - c > 0) {
                if (get(i, j - c) < get(i, j)) {
                    j -= c;
                    f = 1;
                    continue;
                }
            }
        }
        return {i, j};
    }

int32_t main() {

    return 0;
}
