#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back

ll value(int r, int c);

const int MAXN = 500 + 7;

int a[MAXN][MAXN];

pair<int, int> res = {-1, -1};

void dfs(int l, int c) {
    if (a[l][c] == -1) a[l][c] = value(l, c);
    bool ok = 1;
    for (int d = 0; d < 4; ++d) {
        int x = l + dx[d], y = r + dy[d];
        if (1 <= x && x <= n && 1 <= y && y <= m) {
            if (a[x][y] == -1) a[x][y] = value(x, y);
            if (a[x][y] < a[l][c]) {
                dfs(x, y);
                ok = 0;
                break;
            }
        }
    }
    if (ok) res = {l, c};
}

pair<int, int> find_locmin_point(int n, int m) {
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            a[i][j] = -1;
        }
    }
    dfs(1, 1);
    return res;
}
