#include <bits/stdc++.h>
using namespace std;
int num[1005][1005];
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }
int main() {
  int n, m, i, j, k;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; ++i)
    for (j = 0; j < m; ++j) scanf("%d", num[i] + j);
  int ans = -1;
  for (i = 0; i < n; ++i)
    for (j = i + 1; j < n; ++j) {
      int a = 0, b = 0, t;
      for (k = 0; k < m; ++k) {
        t = fastMin(num[i][k], num[j][k]);
        if (t > a)
          b = a, a = t;
        else if (t > b)
          b = t;
      }
      ans = fastMax(ans, b);
    }
  printf("%d\n", ans);
  return 0;
}
