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

mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());

long long value(int r, int c);

long long a[510][510];

vector <pair<int, int>> d = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

std::pair<int, int> find_locmin_point(int n, int m) {
    if (n == 1) {
        int l = 1, r = m;
        a[1][1] = value(1, 1);
        if (m == 1) return make_pair(1, 1);
        a[1][2] = value(1, 2);
        if (m == 2) {
            if (a[1][1] < a[1][2]) return make_pair(1, 1);
            else return make_pair(1, 2);
        }
        if (a[1][1] < a[1][2]) return make_pair(1, 1);
        a[1][r] = value(1, r);
        if (m == 3) {
            if (a[1][2] < a[1][3]) return make_pair(1, 2);
            else return make_pair(1, 3);
        }
        a[1][r - 1] = value(1, r - 1);
        if (a[1][r] < a[1][r - 1]) return make_pair(1, r);
        if (m == 4) {
            if (a[1][2] < a[1][3]) return make_pair(1, 2);
            else return make_pair(1, 3);
        }
        l = 2; r = m - 1;
        while (l < r) {
            int mid = (l + r) / 2;
            if (a[1][mid] == 0) a[1][mid] = value(1, mid);
            if (a[1][mid + 1] == 0) a[1][mid + 1] = value(1, mid + 1);
            if (a[1][mid] > a[1][mid + 1]) l = mid + 1;
            else r = mid;
        }
        return make_pair(1, r);
    }
    
    int i = gen(), j = gen();
    i = abs(i) % n + 1; j = abs(j) % m + 1;
    a[i][j] = value(i, j);
    for (int it = 1; it < 500; it++) {
        int x = gen(), y = gen();
        x = abs(x) % n + 1; y = abs(y) % m + 1;
        if (a[x][y] == 0) a[x][y] = value(x, y);
        if (a[x][y] < a[i][j]) {
            i = x; j = y;
        }
    }
    bool flag = 1;
    while (flag) {
        shuffle(d.begin(), d.end(), gen);
        flag = 0;
        for (auto to : d) {
            int x = i + to.first, y = j + to.second;
            if (x < 1 || x > n || y < 1 || y > m) continue;
            if (a[x][y] == 0) a[x][y] = value(x, y);
            if (a[x][y] < a[i][j]) {
                i = x; j = y;
                flag = 1; break;
            }
        }
    }
    return make_pair(i, j);
}
