#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const int days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int leap[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a[1111][1111];
long long b[1111][20];
int n, m;
bool chk(int mid) {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 17; ++j) b[i][j] = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (a[i][j] >= mid) b[i][j / 60] |= (1LL << (j % 60));
  bool bi = true;
  for (int i = 0; bi && i < n; ++i)
    for (int j = i + 1; bi && j < n; ++j) {
      int ret = 0;
      for (int k = 0; bi && k < 17; ++k) {
        ret += __builtin_popcountll(b[i][k] & b[j][k]);
        if (ret > 1) bi = false;
      }
    }
  if (bi) return false;
  return true;
}
vector<int> V;
int main() {
  while (scanf("%d%d", &n, &m) == 2) {
    V.clear();
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) {
        scanf("%d", &a[i][j]);
        V.push_back(a[i][j]);
      }
    sort(V.begin(), V.end());
    int l = 0, r = V.size(), mid;
    while (l < r - 1) {
      mid = (l + r) >> 1;
      if (chk(V[mid]))
        l = mid;
      else
        r = mid;
    }
    cout << V[l] << endl;
  }
  return 0;
}
