#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 1000 + 7;
int a[MAX][MAX];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = (0); i < (n); i++) {
    for (int j = (0); j < (m); j++) cin >> a[i][j];
  }
  int maxx, ans = -1;
  for (int i1 = (0); i1 < (n); i1++) {
    for (int i2 = (i1 + 1); i2 < (n); i2++) {
      maxx = min(a[i1][0], a[i2][0]);
      for (int j = (1); j < (m); j++) {
        int minn = min(a[i1][j], a[i2][j]);
        ans = max(ans, min(maxx, minn));
        maxx = max(maxx, minn);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
