#include <bits/stdc++.h>
using namespace std;
const long long LLINF = 1e18;
const int INF = 1e9;
const int MOD = 20101009;
const int HMOD = 999959;
const int VMOD = 5000000;
const int MAXN = 3e5 + 10;
const int MAXM = 5e5 + 10;
const int INV = 10050505;
const long long LLINV = 1e18;
const double eps = 1e-3;
int dirx[5] = {0, -1, 1, 0, 0}, diry[5] = {0, 0, 0, -1, 1};
int n, m;
int a[20][10010];
int adj[20][20];
int dp[17][17][(1 << 16)];
int cal(int x, int y) {
  int val = 1e9;
  for (int i = 1; i <= m; ++i) val = min(val, abs(a[x][i] - a[y][i]));
  return val;
}
int caldif(int x, int y) {
  int val = 1e9;
  for (int i = 1; i < m; ++i) val = min(val, abs(a[x][i] - a[y][i + 1]));
  return val;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j <= m; ++j) scanf("%d", &a[i][j]);
  }
  if (n == 1) {
    int ans = 1e9;
    for (int i = 1; i < m; ++i) ans = min(ans, abs(a[0][i] - a[0][i + 1]));
    printf("%d\n", ans);
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      adj[i][j] = adj[j][i] = cal(i, j);
    }
  }
  for (int i = 0; i < n; ++i) dp[i][i][(1 << i)] = 1e9;
  for (int i = 0; i < n; ++i) {
    for (int s = 0; s < (1 << n); ++s) {
      for (int j = 0; j < n; ++j) {
        for (int k = 0; k < n; ++k) {
          if (((s >> i) & 1) == 0) continue;
          if (((s >> j) & 1) == 0) continue;
          if ((s >> k) & 1) continue;
          dp[i][k][s | (1 << k)] =
              max(dp[i][k][s | (1 << k)], min(dp[i][j][s], adj[j][k]));
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (i != j) ans = max(ans, min(dp[i][j][(1 << n) - 1], caldif(j, i)));
  printf("%d\n", ans);
  return 0;
}
