#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 10;
int a[N][N], n, m, ans;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      int mx = -1;
      for (int k = 1; k <= m; k++) {
        int res = min(a[i][k], a[j][k]);
        ans = max(ans, min(res, mx));
        mx = max(mx, res);
      }
    }
  cout << ans;
}
