#include <bits/stdc++.h>
using namespace std;
int mat[1009][1009];
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = int(0); i <= int(n - 1); i++) {
    for (int j = int(0); j <= int(m - 1); j++) {
      scanf("%d", &mat[i][j]);
    }
  }
  int ans = -1 * 2000000000;
  for (int i = int(0); i <= int(n - 1); i++) {
    for (int k = int(i + 1); k <= int(n - 1); k++) {
      pair<int, int> mini = pair<int, int>(-1 * 2000000000, -1 * 2000000000);
      for (int j = int(0); j <= int(m - 1); j++) {
        int val = min(mat[i][j], mat[k][j]);
        if (val > mini.first) {
          mini.second = mini.first;
          mini.first = val;
        } else if (val > mini.second)
          mini.second = val;
      }
      ans = max(ans, mini.second);
    }
  }
  printf("%d\n", ans);
  return 0;
}
