#include <bits/stdc++.h>
int B, X, Y, N, M, A[1005][1005];
using namespace std;
int main() {
  scanf("%d%d", &N, &M);
  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; i++)
    for (int j = i + 1; j < N; j++) {
      X = Y = 0;
      for (int k = 0; k < M; k++)
        if (A[j][k] > B && A[i][k] > B) {
          X = max(X, min(A[i][k], A[j][k]));
          if (X > Y) swap(X, Y);
        }
      B = max(B, X);
    }
  printf("%d", B);
}
