#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m, f[17][17][1 << 17 - 1], b[17][17], a[17][11000];
void update(int &x, int k) {
  if (x < k) x = k;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      b[i][j] = INF;
      for (int k = 1; k <= m; k++) {
        b[i][j] = min(b[i][j], abs(a[i][k] - a[j][k]));
      }
    }
  memset(f, 0, sizeof(f));
  for (int i = 1; i <= n; i++) {
    f[i][i][1 << i - 1] = INF;
  }
  for (int k = 0; k < (1 << n); k++) {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) {
        if (((1 << i - 1) & k) && ((1 << j - 1) & k)) {
          for (int t = 1; t <= n; t++) {
            if (!((1 << t - 1) & k)) {
              update(f[i][t][k | (1 << t - 1)], min(f[i][j][k], b[j][t]));
            }
          }
        }
      }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      int k = f[i][j][(1 << n) - 1];
      for (int p = 1; p < m; p++) {
        k = min(k, abs(a[i][p] - a[j][p + 1]));
      }
      ans = max(ans, k);
    }
  cout << ans;
  return 0;
}
