#include "locmin.h"
#include <cassert>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
// #define ll ll

ll _n, _m;
std::pair<ll, ll> ans;
std::vector<std::vector<ll>> asked;

void solve1() {
    assert(_n == 1);
    ll l = 1, r = _m, mid;
    while (l <= r) {
        if (asked[1][l] == -1)
            asked[1][l] = value(1, l);
        if (asked[1][r] == -1)
            asked[1][r] = value(1, r);
        mid = (l + r) >> 1;
        if (asked[1][mid] == -1) 
            asked[1][mid] = value(1, mid);
        if (asked[1][l] <= asked[1][mid] && asked[1][mid] <= asked[1][r]) {
            ;
        }
    }
}

void solve() {
    for (size_t i = 1; i <= _n; i++) {
        for (size_t j = 1; j <= _m; j++) {
            asked[i][j] = value(i, j);
        }
    }
    for (size_t i = 1; i <= _n; i++) {
        for (size_t j = 1; j <= _m; j++) {
            if (asked[i][j] < asked[i][j + 1] && asked[i][j] < asked[i + 1][j] && asked[i][j] < asked[i - 1][j] && asked[i][j] < asked[i][j - 1]) {
                ans = make_pair(i, j);
            }
        }
    }
}


void systemd() {
    ans = std::make_pair(-1, -1);
    asked.assign(_n + 2, vector<ll>(_m + 2, 1e18 + 1));
}

std::pair<int, int> find_locmin_point(int N, int M) {
    _n = N, _m = M;
    systemd();
    // if (N == 1) {
    //     solve1();
    //     assert(ans.first != -1);
    //     return ans;
    // }
    solve();
    assert(ans.first != -1);
    return ans;
}
