#include<bits/stdc++.h>
#include "locmin.h"
using namespace std;
std::pair <int, int> find_locmin_point(int N, int M)
{
    int currx=1,curry=1;long long curr=value(1,1);
    while (true)
    {
        vector<pair<long long,pair<int,int>>> values;
        if (currx!=1) values.push_back({value(currx-1,curry),{currx-1,curry}});
        if (currx!=N) values.push_back({value(currx+1,curry),{currx+1,curry}});
        if (curry!=1) values.push_back({value(currx,curry-1),{currx,curry-1}});
        if (curry!=M) values.push_back({value(currx,curry+1),{currx,curry+1}});
        sort(values.begin(),values.end());
        if (values[0].first>curr) return {currx,curry};
        currx=values[0].second.first,curry=values[0].second.second;
    }
}