#include <bits/stdc++.h>
using namespace std;

long long value(int r, int c);

long long a[510][510];

std::pair<int, int> find_locmin_point(int n, int m) {
  
    int i = rand() % n + 1;
    int j = rand() % m + 1;
    if (a[i][j] == 0) a[i][j] = value(i, j);
    while (1) {
        if (i > 1 && a[i - 1][j] == 0) a[i - 1][j] = value(i - 1, j);
        if (i < n && a[i + 1][j] == 0) a[i + 1][j] = value(i + 1, j);
        if (j > 1 && a[i][j - 1] == 0) a[i][j - 1] = value(i, j - 1);
        if (j < m && a[i][j + 1] == 0) a[i][j + 1] = value(i, j + 1);
        pair<int, pair<int, int>> mn = {a[i][j], {i, j}};
        if (i > 1) mn = min(mn, {a[i - 1][j], {i - 1, j}});
        if (i < n) mn = min(mn, {a[i + 1][j], {i + 1, j}});
        if (j > 1) mn = min(mn, {a[i][j - 1], {i, j - 1}});
        if (j < m) mn = min(mn, {a[i][j + 1], {i, j + 1}});
        if (mn == a[i][j]) return make_pair(i, j);
        tie(i, j) mn.second;
    }
    return make_pair(i, j);
}
