#include<bits/stdc++.h>
using namespace std;
vector<pair<int, int>> dirs = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
long long value(int r, int c);
long long mem[510][510];
pair<int, int> find_locmin_point(int N, int M){
		for(int i = 1; i <= N; i++){
			for(int j = 1; j <= M; j++){
				bool fl = true;
				long long p;
				if(mem[i][j] != 0) p = mem[i][j];
				else p = value(i, j);
				for(auto [xx, yy]: dirs){
					int x = i + xx;
					int y = j + yy;
					if(x < 1 || x > N || y < 1 || y > M) continue;
					long long val;
					if(mem[x][y] != 0) val = mem[x][y];
					else val = value(x, y);
					if(val < p){
						fl = false;
						break;
					}
				}
				if(fl){
					return {i, j};
				}
			}
		}
}
