#include "locmin.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector <vector <ll>> v;
int n, m;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
ll get(int x, int y) {
    if (v[x][y] == -1) v[x][y] = value(x, y);
    return v[x][y];
}
pair <int, int> find_locmin_point(int N, int M) {
    n = N, m = M;
    v.assign(N+1, vector <ll>(M+1, -1));
    v[1][1] = get(1, 1);
    int l = 1, r = m;
    while (l < r) {
        int ml = l + (r - l) / 3;
        int mr = r - (r - l) / 3;
        if (get(1, ml) < get(1, mr)) {
            r = mr - 1;
        }
        else if (get(1, ml) > get(1, mr)) {
            l = ml + 1;
        }
        else {
            ml++;
            if (get(1, ml) < get(1, mr)) {
                r = mr - 1;
            }
            else{
                l = ml + 1;
            }
        }
    }
    return {1, l};
}
