#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
vector <vector <ll> > a;
long long value(int r, int c);
std::pair <int, int> find_locmin_point(int N, int M){
    if(N == 1 && M == 1) return {1, 1};
    ll lo = 2, ro = M - 1;
    vector <ll> r(M+1, -1);
    r[1] = value(1, 1);
    r[2] = value(1, 2);
    r[M] = value(1, M);
    r[M - 1] = value(1, M - 1);
    if(r[1] < r[2]) return {1, 1};
    if(r[M] < r[M-1]) return {1, M};
    while(lo != ro){
        ll tm = (lo + ro) / 2;
        ll a, b, c;
        if(r[tm - 1] == -1)
        a = value(1, tm-1);
        else a = r[tm - 1];
        if(r[tm] == -1)
        b = value(1, tm);
        else b = r[tm];
        if(r[tm + 1] == -1)
            c = r[tm+1];
        else c = value(1, tm + 1);
        r[tm - 1] = a;
        r[tm] = b;
        r[tm + 1] = c;
        if(b < a && b < c) return {1, tm};
        if(a > b && b > c)
            lo = tm + 1;
        else ro = tm;
    }
    return {1, lo};
}