#include <bits/stdc++.h>
using namespace std;
int a[16][10005], mini[16][16];
int D[1 << 16][16];
int main() {
  int n, m;
  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 = 0; j < n; j++) {
      mini[i][j] = 1e9;
      for (int k = 0; k < m; k++)
        mini[i][j] = min(mini[i][j], abs(a[i][k] - a[j][k]));
    }
  }
  int ans = 0;
  for (int l = 0; l < n; l++) {
    memset(D, 0, sizeof(D));
    D[1 << l][l] = 1e9;
    for (int i = 1; i < (1 << n); i++) {
      for (int j = 0; j < n; j++) {
        if (!((i >> j) & 1)) continue;
        for (int k = 0; k < n; k++) {
          if (!((i >> k) & 1)) {
            D[i + (1 << k)][k] =
                max(D[i + (1 << k)][k], min(D[i][j], mini[j][k]));
          }
        }
      }
    }
    int i = (1 << n) - 1;
    for (int j = 0; j < n; j++) {
      int minini = D[i][j];
      for (int k = 0; k < m - 1; k++)
        minini = min(minini, abs(a[j][k] - a[l][k + 1]));
      ans = max(ans, minini);
    }
  }
  printf("%d", ans);
  return 0;
}
