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

long long value(int r, int c);

constexpr long long inf = 2'000'000'000'000'000'000;

struct Gridrememberer {
    Gridrememberer(int n, int m) : size(n, vector<long long>(m, -1)), x(n), y(m) {}

    long long get_value(int n, int m) {
        if (n < 0 || m < 0 || n >= x || m >= y) {
            return inf;
        }

        if (size[n][m] != -1) {
            return size[n][m];
        }

        return size[n][m] = value(n + 1, m + 1);
    }

    vector<vector<long long>> size;

    int x, y;
};

std::pair<int, int> find_locmin_point(int n, int m) {
    Gridrememberer grid(n, m);

    int mix = 0;
    int miy = 0;

    int max = n;
    int may = m;

    bool sw = false;

    while (mix + 1 < max || miy + 1 < may) {
        if (may - miy > max - mix) {
            sw = !sw;

            swap(mix, miy);
            swap(max, may);
        }

        int mid = (mix + max) / 2;

        long long mi_wert = inf;
        bool links = true;

        for (int y = miy; y < may; ++y) {
            if (!sw) {
                if (grid.get_value(mid - 1, y) < mi_wert) {
                    links = true;
                    mi_wert = grid.get_value(mid - 1, y);
                };

                if (grid.get_value(mid, y) < mi_wert) {
                    links = false;
                    mi_wert = grid.get_value(mid, y);
                }
            } else {
                if (grid.get_value(y, mid - 1) < mi_wert) {
                    links = true;
                    mi_wert = grid.get_value(y, mid - 1);
                };

                if (grid.get_value(y, mid) < mi_wert) {
                    links = false;
                    mi_wert = grid.get_value(y, mid);
                }
            }
        }

        if (links) {
            max = mid;
        } else {
            mix = mid;
        }
    }

    if (sw) {
        swap(mix, miy);
        swap(max, may);
    }

    return {mix + 1, miy + 1};
}