#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m;
int a[N][N];
int main() {
  scanf("%d%d", &n, &m);
  int res, res1, res2;
  res = -1;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &a[i][j]);
  for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++) {
      res1 = res2 = -1;
      for (int k = 0; k < m; k++) {
        if (min(a[i][k], a[j][k]) > res2) {
          res1 = res2;
          res2 = min(a[i][k], a[j][k]);
        } else
          res1 = max(res1, min(a[i][k], a[j][k]));
      }
      res = max(res, res1);
    }
  printf("%d", res);
  return 0;
}
