#include <bits/stdc++.h>
#define MAXN 500
#define fi first
#define se second
#include "locmin.h"
using namespace std;
long long val[MAXN+5][MAXN+5];

pair<int, int> find_locmin_point(int N, int M) {
    int i, j;
    for (i=1; i<=N; i++) {
        for (j=1; j<=M; j++) {
            val[i][j]=value(i, j);
        }
    }
    for (i=1; i<=N; i++) {
        for (j=1; j<=M; j++) {
            if (i>1 && val[i-1][j]<val[i][j]) continue;
            if (i<N && val[i+1][j]<val[i][j]) continue;
            if (j>1 && val[i][j-1]<val[i][j]) continue;
            if (j<M && val[i][j+1]<val[i][j]) continue;
            return {i, j};
        }
    }
}
