long long value(int r, int c);
bool ck(int x, int y, int N, int M)
{
    if (1 <= x && x <= N && 1 <= y && y <= M) return true;
    else return false;
}
std::pair<int, int> find_locmin_point(int N, int M)
{
    long long a[501][501];
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= M; j++)
        {
            a[i][j] = value(i,j);
        }
    }
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= M; j++)
        {
            bool bul = true;
            int x, y;
            x = i; y = j+1;
            if (ck(x,y,N,M) && a[x][y] < a[i][j]) bul = false;
            x = i; y = j-1;
            if (ck(x,y,N,M) && a[x][y] < a[i][j]) bul = false;
            x = i+1; y = j;
            if (ck(x,y,N,M) && a[x][y] < a[i][j]) bul = false;
            x = i-1; y = j;
            if (ck(x,y,N,M) && a[x][y] < a[i][j]) bul = false;
            if (bul) return {i,j};
        }
    }
}