#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
vector <vector <ll> > a;
long long value(int r, int c){
    return a[r][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);
    if(r[1] < r[2]) return {1, 1};
    if(r[M] == -1)
    r[M] = value(1, M);
    if(r[M-1] == -1)
    r[M - 1] = value(1, M - 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)
        a = value(1, tm);
        else a = r[tm];
        if(r[tm+1] == -1)
        b = value(1, tm+1);
        else b = r[tm+1];
        r[tm - 1] = a;
        r[tm] = b;
        if(a < b) ro = tm;
        else lo = tm + 1;
    }
    return {1, lo};
}