#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second

using ll = long long;
using pii = pair<int, int>;

ll value(int r, int c);

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

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

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

int cnt;

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

bool check(int i, int j) {
   ll val = query(i, j);
   return val < query(i + 1, j) && val < query(i - 1, j) && val < query(i, j + 1) && val < query(i, j - 1);
}

#define CHECK(i, j) if (check(i, j)) return { i, j }

pii divide(int l1, int r1, int l2, int r2) {
   if (l1 >= r1 && l2 >= r2) {
      CHECK(l1, r1);
      return {};
   }

   if ((r1 - l1 - 1) * (r2 - l2 - 1) < 2026 - cnt) {
      for (int i = l1; i <= r1; i++) {
         for (int j = l2; j <= r2; j++) {
            CHECK(i, j);
         }
      }
   }

#if 0
   if (l1 == r1) {
      while (l2 < r2) {
         int mid = (l2 + r2) / 2;
         if (query(l1, mid) < query(l1, mid + 1)) {
            r2 = mid;
            CHECK(l1, mid);
         } else {
            l2 = mid + 1;
            CHECK(l1, mid + 1);
         }
      }
      return {};
   }

   if (l2 == r2) {
      while (l1 < r1) {
         int mid = (l1 + r1) / 2;
         if (query(mid, l2) < query(mid + 1, l2)) {
            r1 = mid;
            CHECK(mid, l2);
         } else {
            l1 = mid + 1;
            CHECK(mid + 1, l2);
         }
      }
      return {};
   }
#endif

   ll mn = INF;
   int x = (l1 + r1) / 2;
   int y = (l2 + r2) / 2;

   for (int k = 0; k < 4; k++) {
      mn = min(mn, query(x + dx[k], y + dy[k]));
      CHECK(x + dx[k], y + dy[k]);
   }

   if (query(x, y) == mn) {
      pii ans = divide(l1, x, l2, y);
      if (ans.fi) return ans;
   }
   if (query(x + 1, y) == mn) {
      pii ans = divide(x + 1, r1, l2, y);
      if (ans.fi) return ans;
   }
   if (query(x, y + 1) == mn) {
      pii ans = divide(l1, x, y + 1, r2);
      if (ans.fi) return ans;
   }
   if (query(x + 1, y + 1) == mn) {
      pii ans = divide(x + 1, r1, y + 1, r2);
      if (ans.fi) return ans;
   }
   
   return {};
}

pii find_locmin_point(int N, int M) {
   n = N;
   m = M;

   return divide(1, n, 1, 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

