#include <bits/stdc++.h>

using namespace std;
using ll = long long;


ll value(int i, int j);

map < array < int , 2 > , ll > res;

ll val(int i, int j) {
    if (res.count({i, j})) return res[{i, j}];
    return res[{i, j}] = value(i, j);
}

int get(int i, int m) {
    if (m == 1) return 1;

    int l = 1, r = m;

    while (l < r) {
        int mid = (l + r) >> 1;
        ll x = val(i, mid);
        ll y = val(i, mid + 1);
        if (y < x) { l = mid + 1; continue; }
        else {
            if (mid == 1) return 1;
            ll z = val(i, mid - 1);
            if (z < x) r = mid - 1;
            else return mid;
        }
    }

    return l;
}

pair < int , int > find_locmin_point(int n, int m) {
    res.clear();

    for (int i = 1; i <= n; i++) {
        int p = get(i, m);
        bool bad = 0;
        ll x = val(i, p);
        if (i > 1) if (val(i - 1, p) < x) bad = 1;
        if (i < n) if (val(i + 1, p) < x) bad = 1;
        if (!bad) return make_pair(i, p);
    }

    exit(1);
}
