#include <bits/stdc++.h>

using namespace std;

long long value(int r, int c);

std::pair<int, int> find_locmin_point(int n, int m){
    pair<int,int> curr = {n/2,m/2};
    int val = value (n/2,m/2);
    while(true){
        pair<int,int> next = {-1,-1};
        int new_val=val;
        if(curr.first<n-1){
            int x = value(curr.first+1,curr.second);
            if(x<val && new_val > x){
                next = {curr.first+1,curr.second};
                new_val = x;
            }
        }
        if(curr.first>0){
            int x = value(curr.first-1,curr.second);
            if(x<val && new_val > x){
                next = {curr.first-1,curr.second};
                new_val = x;
            }
        }
        if(curr.first<n-1){
            int x = value(curr.first,curr.second+1);
            if(x<val && new_val > x){
                next = {curr.first,curr.second+1};
                new_val = x;
            }
        }
        if(curr.first<n-1){
            int x = value(curr.first+1,curr.second-1);
            if(x<val && new_val > x){
                next = {curr.first,curr.second-1};
                new_val = x;
            }
        }
        if(next.first == -1) return curr;
        
        curr = next;
    }
}
