#include "locmin.h"
#include <bits/stdc++.h>
using namespace std;

#define speedup cin.tie(0) -> sync_with_stdio(0);
#define all(x) begin(x), end(x);
#define pb push_back
#define vc vector

using ll = long long;

vc<vc<int>> s;
inline int get (int i, int j) {
    int res = s[i][j];
    if (res == -1) {
        res = value(i, j);
        s[i][j] = res;
    } return res;
}

vc<array<int, 2>> dr = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
pair<int, int> find_locmin_point(int n, int m) {
    s.assign(n + 1, vc<int> (m + 1, -1));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int cnt = 0; get(i, j);
            for (auto [di, dj] : dr) {
                int ni = i + di, nj = j + dj;
                if (ni < 1 || ni > n || nj < 1 || nj > m) {
                    cnt++;
                    continue;
                }

                if (get(ni, nj) > s[i][j]) cnt++;
            }

            if (cnt == 4) return {i, j};
        }
    }
    return {-1, -1};
}

/*
3 4
5 3 5 6
10 6 4 10
2 9 8 2
*/