#include <bits/stdc++.h>
using namespace std;
int m, n, a[17][10001];
int g[17][17], g1[17][17];
int dis(int i, int j) {
  int kq = 1000000007;
  for (int v = 1; v <= n; ++v) kq = min(kq, abs(a[i][v] - a[j][v]));
  return kq;
}
int nho[1 << 17][17], dp[1 << 17][17];
int xp;
int calc(int x, int i) {
  if (x == (1 << (i - 1))) return (i == xp) ? 1000000007 : 0;
  if ((x & (1 << (xp - 1))) == 0) return -1;
  if (nho[x][i] == xp) return dp[x][i];
  nho[x][i] = xp;
  dp[x][i] = 0;
  int y = x ^ (1 << (i - 1));
  for (int j = 1; j <= m; ++j)
    if ((y >> (j - 1)) & 1) {
      dp[x][i] = max(dp[x][i], min(calc(y, j), g[i][j]));
    }
  return dp[x][i];
}
int kc(int i, int j) {
  int kq = 1000000007;
  for (int v = 1; v < n; ++v) kq = min(kq, abs(a[i][v] - a[j][v + 1]));
  return kq;
}
int main() {
  scanf("%d %d", &m, &n);
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= n; ++j) scanf("%d", &a[i][j]);
  for (int i = 1; i <= m; ++i)
    for (int j = i + 1; j <= m; ++j) g[i][j] = g[j][i] = dis(i, j);
  for (int i = 1; i <= m; ++i)
    for (int j = 1; j <= m; ++j) g1[i][j] = kc(i, j);
  int ans = 0;
  for (xp = 1; xp <= m; ++xp) {
    for (int i = 1; i <= m; ++i)
      if (i != xp) ans = max(ans, min(calc((1 << m) - 1, i), g1[i][xp]));
  }
  if (m == 1) {
    ans = 1000000007;
    for (int v = 2; v <= n; ++v) ans = min(ans, abs(a[1][v] - a[1][v - 1]));
  }
  printf("%d", ans);
}
