#include <iostream>
#include <cstdint>

using namespace std;
using pair_t = pair<int, int>;

const int64_t max_val = INT64_MAX;

long long value(int r, int c);

pair_t find_locmin_point(int N, int M) {
    int64_t grid[502][502];
    for (uint16_t i = 1; i <= M; i++) {
        grid[1][i] = value(1, i);
    }
    for (uint16_t i = 0, e = M + 1, r = N + 1; i <= e; i++) {
        grid[0][i] = max_val;
        grid[r][i] = max_val;
    }
    for (uint16_t i = 1, c = M + 1; i <= N; i++) {
        grid[i][0] = max_val;
        grid[i][c] = max_val;
    }
    uint16_t i, j;
    for (i = 1; i < N; i++) {
        for (j = 1; j <= M; j++) {
            int64_t cur_grid = grid[i][j];
            int64_t below_grid = value(i + 1, j);
            grid[i + 1][j] = below_grid;
            if (cur_grid < below_grid && cur_grid < grid[i - 1][j] && cur_grid < grid[i][j + 1] && cur_grid < grid[i][j - 1]) {
                return {i, j};
            }
        }
    }
    for (i = 1; i <= M; i++) {
        int64_t cur_grid = grid[N][i];
        if (cur_grid < grid[N + 1][i] && cur_grid < grid[N - 1][i] && cur_grid < grid[N][i + 1] && cur_grid < grid[N][i - 1]) {
            return {N, i};
        }
    }
}