#include <bits/stdc++.h>
using namespace std;
const int maxn = 18;
const int maxm = 1e4 + 10;
const int inf = 0x3f3f3f3f;
int n, m;
int niz[maxn][maxm];
int pre1[maxn][maxn], pre2[maxn][maxn];
int dp[1 << maxn][maxn];
int f(int mask, int poc, int tren) {
  if (mask == (1 << n) - 1) return pre2[tren][poc];
  int &ret = dp[mask][tren];
  if (ret != -1) return ret;
  ret = -inf;
  for (int i = 0; i < n; i++)
    if ((mask & (1 << i)) == 0)
      ret = max(ret, min(f(mask | (1 << i), poc, i), pre1[tren][i]));
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &niz[i][j]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j && n > 1) continue;
      pre1[i][j] = pre2[i][j] = inf;
      for (int k = 0; k < m; k++)
        pre1[i][j] = min(pre1[i][j], abs(niz[i][k] - niz[j][k]));
      for (int k = 1; k < m; k++)
        pre2[i][j] = min(pre2[i][j], abs(niz[i][k - 1] - niz[j][k]));
    }
  }
  int sol = -inf;
  for (int i = 0; i < n; i++) {
    memset(dp, -1, sizeof dp);
    sol = max({sol, f((1 << i), i, i), pre1[i][i]});
  }
  printf("%d", sol);
  return 0;
}
