#include <bits/stdc++.h>
#include "locmin.h"

using namespace std;

vector<int> dx{0, -1, 0, 1};
vector<int> dy{-1, 0, 1, 0};

pair<int, int> find_locmin_point(int n, int m) {
    vector<vector<long long>> a(n, vector<long long>(m));
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++)
            a[i][j] = value(i + 1, j + 1);
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            long long Min = LLONG_MAX;
            for (int k = 0; k < 4; k++) {
                int x = i + dx[k], y = j + dy[k];
                
                if (x < 0 || x > n - 1 || y < 0 || y > m - 1)
                    continue;
                
                Min = min(Min, a[x][y]);
            }
        
            if (Min > a[i][j])
                return {i + 1, j + 1};
        }
    }
    
    return {-1, -1};
}