#include <bits/stdc++.h>

using namespace std;

using ll = long long;

ll value(int r, int c);

const int NMAX = 505;
const ll INF = 1.1e18;

#define check(i, j) \
   if (int val = query(i, j); val < query(i + 1, j) && val < query(i - 1, j) && val < query(i, j + 1) && val < query(i, j - 1)) return { i, j }

const int dx[] = { 0, 0, 1, -1 };
const int dy[] = { 1, -1, 0, 0 };

int n, m;
ll a[NMAX][NMAX];

ll query(int x, int y) {
   if (x < 1 || y < 1 || x > n || y > m) return INF;
   return a[x][y] ? a[x][y] : a[x][y] = value(x, y);
}

pair<int, int> find_locmin_point(int N, int M) {
   n = N;
   m = M;

   if (n == 1) {
      int l = 1, r = m;
      while (l + 1 < r) {
         int mid = (l + r) / 2;
         if (query(1, mid) < query(1, mid + 1)) {
            r = mid;
            check(1, mid);
         } else {
            l = mid;
            check(1, mid + 1);
         }
      }
   }

   int x = 1, y = 1;

   while (true) {
      check(x, y);
      ll mn = INF;
      for (int k = 0; k < 4; k++) {
         mn = min(mn, query(x + dx[k], y + dy[k]));
      }
      for (int k = 0; k < 4; k++) {
         if (query(x + dx[k], y + dy[k]) == mn) {
            x += dx[k];
            y += dy[k];
            break;
         }
      }
   }

   return { n, m };
}

#ifdef LOCAL

ll _a[NMAX][NMAX];
ll value(int r, int c) {
   return _a[r][c];
}

signed main() {
   freopen("input.txt", "r", stdin);
   int n, m;
#if 0
   n = 500, m = 500;
   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
   for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
         _a[i][j] = abs(int(rng()));
      }
   }
#else
   cin >> n >> m;
   for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
         cin >> _a[i][j];
      }
   }
#endif
   auto [ x, y ] = find_locmin_point(n, m);
   cout << x << ' ' << y << endl;

   int val = query(x, y);
   assert(val < query(x + 1, y));
   assert(val < query(x - 1, y));
   assert(val < query(x, y + 1));
   assert(val < query(x, y - 1));

   return 0;
}

#endif
