#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
long long value(int r, int c);
std::pair<int, int> find_locmin_point(int N, int M) {
    if (N == 1) {
        int l = 1, r = M;
        map<int, long long> mp;
        mp[0] = 1e18;
        mp[M + 1] = 1e18;
        auto que = [&](int j) {
            if (mp.find(j) != mp.end()) return mp[j];
            return mp[j] = value(1, j);
        };
        while (true) {
            if (l >= r) break;
            if (l + 1 == r) {
                if (que(l - 1) > que(l) && que(l + 1) > que(l)) l = l;
                else l++;
                break;
            }
            int mid = (l + r) >> 1;
            if (que(mid) < que(mid + 1)) r = mid;
            else l = mid;
        }
        return std::pair<int, int>{1, l};
    }
    vector<vector<long long>> mp(N + 1, vector<long long>(M + 1, -1));
    auto ask = [&](int i, int j) {
        if (i == 0 || i == N + 1 || j == 0 || j == M + 1) return (long long)1e18;
        if (mp[i][j] != -1) return mp[i][j];
        return mp[i][j] = value(i, j);
    };
    vector<pair<int, int>> to = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= M; ++j) {
            bool flag = true;
            for (auto [a1, a2] : to) {
                int ti = i + a1, tj = j + a2;
                if (1 <= ti && ti <= N && 1 <= tj && tj <= M) {
                    if (ask(ti, tj) <= ask(i, j)) flag = false;
                }
            }
            if (flag) return std::pair<int, int>{i, j};
        }
    }
}
/*signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    auto [a1, a2] = find_locmin_point(3, 4);
    cout << a1 << ' '<< a2 << endl;
    return 0;
}*/
