#include <bits/stdc++.h>
using namespace std;
const char IO_MODE = 3;
inline long long ReadInt() {
  long long x = 0, s = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') s = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return s * x;
}
inline void WriteInt(long long x) {
  char c[20];
  if (!x) {
    putchar('0');
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  int i = 0;
  while (x > 0) c[++i] = x % 10, x /= 10;
  while (i) putchar(c[i--] + 48);
}
template <typename T>
inline void out(T x) {
  if (IO_MODE & 1)
    WriteInt(x);
  else if (typeid(x) == typeid(int))
    printf("%i", x);
  else
    printf("%lld", (long long)x);
}
template <typename T, typename... Args>
inline void out(T x, Args... args) {
  out(x);
  putc(' ', stdout);
  out(args...);
}
template <typename T>
inline void in(T &x) {
  if (IO_MODE & 2)
    x = ReadInt();
  else if (typeid(x) == typeid(int))
    scanf("%i", &x);
  else if (typeid(x) == typeid(long long))
    scanf("%lld", &x);
}
template <typename T, typename... Args>
inline void in(T &x, Args &...args) {
  in(x);
  in(args...);
}
int aa, bb, cc, dd, ee, ff, gg, hh, ii, jj, kk, mm, nn, oo, pp, qq, rr, ss, tt,
    uu, vv, ww, xx, yy, zz;
int tc;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug &operator<<(const c &) {
    return *this;
  }
};
int n, m;
int A[300100][9], B[300100][9];
int cur[300100];
int res[1 << 9];
vector<pair<int, pair<int, int> > > v[9];
int main() {
  in(n, m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) in(A[i][j]);
    for (int j = 0; j < m; j++) {
      int mask = 0;
      for (int k = 0; k < m; k++)
        if (A[i][j] > A[i][k]) mask |= 1 << k;
      v[j].push_back(make_pair(A[i][j], make_pair(mask, i)));
    }
  }
  for (int j = 0; j < m; j++) sort(v[j].begin(), v[j].end());
  memset(res, -1, sizeof res);
  pair<int, pair<int, int> > ans = {-1000000007, {-1000000007, -1000000007}};
  int tot = m * n;
  while (tot--) {
    pair<int, int> mxj = {-1000000007, -1000000007};
    for (int j = 0; j < m; j++)
      if (v[j].size()) mxj = max(mxj, make_pair(v[j].back().first, j));
    int jj = mxj.second;
    pair<int, pair<int, int> > x = v[jj].back();
    v[jj].pop_back();
    int val = x.first;
    int mask = x.second.first;
    int i = x.second.second;
    debug() << " ["
            << "mxj"
               ": "
            << (mxj)
            << "] "
               " ["
            << "x"
               ": "
            << (x) << "] ";
    if (res[mask] != -1) {
      ans = max(ans, make_pair(val, make_pair(i, res[mask])));
    } else if (!mask) {
      ans = max(ans, make_pair(val, make_pair(i, i)));
    }
    res[cur[i] |= 1 << jj] = i;
  }
  debug() << " ["
          << "ans"
             ": "
          << (ans) << "] ";
  if (ans.second.second < 0)
    printf("1 1\n");
  else
    cout << ans.second.second + 1 << " " << ans.second.first + 1 << endl;
}
