#include "locmin.h"
#define ll long long
#define INF 1000000000000000001
using namespace std;
#include <bits/stdc++.h>
vector<vector<ll>> v;
int n, m;
ll ask(int x, int y){
    if (x < 1 || x > n || y < 1 || y > m) return INF;
    if (v[x][y] != -1) return v[x][y];
    v[x][y] = value(x, y);
    return v[x][y];
}
std::pair <int, int> find_locmin_point(int N, int M) {
    int l = 1, r = M;
    n = N, m = M;
    v.assign(n + 1, vector<ll>(m + 1, -1));
    while (l <= r){
        cout<<l<<" "<<r<<"\n";
        if (r - l + 1 <= 2){
            for (int i = l; i <= r; i++){
                ll val = ask(1, i);
                if (val < ask(1, i - 1) && val < ask(1, i + 1)) return {1, i};
            }
        }
        int mid = (l + r) / 2;
        int le = ask(1, mid - 1), mi = ask(1, mid), ri = ask(1, mid + 1);
        if (mi < le && mi < ri){
            return {1, mid};
        }
        else if (mi > le){
            l = mid;
        }
        else{
            r = mid;
        }
    }
    return {1, 1};
}
