#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 n, m;
ll a[MAXN][MAXN];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};

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 = c + 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) {
    n = N, m = M;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            a[i][j] = -1;
        }
    }
    dfs(1, 1);
    return res;
}
