#include <bits/stdc++.h>
//#define int long long
#define F first
#define S second
#define pii pair <int, int>
#define ins insert
#define pb push_back
#define ld long double
using namespace std;
int a[501];
long long b[501][501];
long long value(int r, int c);
int bl(int x, int m)
{
    if (x == m) return 0;
    if (!a[x]) a[x] = value(1, x);
    if (!a[x + 1]) a[x + 1] = value(1, x + 1);
    return a[x] > a[x + 1];
}
long long gv(int x, int y)
{
    if (!b[x][y]) b[x][y] = value(x, y);
    return b[x][y];
}
mt19937 gen(chrono::high_resolution_clock()::now().time_since_epoch().count());
pii find_locmin_point(int n, int m)
{
    if (n == 1)
    {
        int l = 1, r = m, ans = 1;
        while (l <= r)
        {
            int mid = (l + r) / 2;
            if (bl(mid, m))
            {
                l = mid + 1;
                ans = mid + 1;
            }
            else
            {
                r = mid - 1;
                ans = mid;
            }
        }
        return {1, ans};
    }

    int t = 100;
    while (t--)
    {
        int x = gen() % n + 1, y = gen() % m + 1;
        x = gv(x, y);
    }

    int x = 1, y = 1;
    while (true)
    {
        set <pair <long long, pii>> st;
        if (x < n) st.ins({gv(x + 1, y), {x + 1, y}});
        if (y < m) st.ins({gv(x, y + 1), {x, y + 1}});
        if (x > 1) st.ins({gv(x - 1, y), {x - 1, y}});
        if (y > 1) st.ins({gv(x, y - 1), {x, y - 1}});
        if ((*st.begin()).F > gv(x, y)) break;
        tie(x, y) = (*st.begin()).S;
    }
    return {x, y};
}
