#include <bits/stdc++.h>
using namespace std;
const int maxn = 17;
const int maxm = 1e4 + 1;
const int maxs = 1 << 16;
const int inf = 1e9 + 7;
int n, m, res;
int a[maxn][maxm], c[maxn][maxn];
int f[maxs][maxn];
inline void Enter() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
}
inline void Init() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j < i; j++) {
      int tmp = inf;
      for (int k = 1; k <= m; k++) tmp = min(tmp, abs(a[i][k] - a[j][k]));
      c[i][j] = c[j][i] = tmp;
    }
}
inline bool GetBit(const int &x, const int &k) { return (x >> k) & 1; }
inline void Solve() {
  res = 0;
  for (int i = 1; i <= n; i++) {
    for (int s = 0; s < maxs; s++)
      for (int j = 0; j < maxn; j++) f[s][j] = -1;
    f[(1 << (i - 1))][i] = inf;
    for (int state = 0; state < (1 << n); state++) {
      for (int j = 1; j <= n; j++) {
        if (!GetBit(state, j - 1)) continue;
        for (int k = 1; k <= n; ++k) {
          if (j == k || !GetBit(state, k - 1)) continue;
          f[state][j] =
              max(f[state][j], min(f[state ^ (1 << (j - 1))][k], c[k][j]));
        }
      }
    }
    for (int j = 1; j <= n; j++) {
      int tmp = f[(1 << n) - 1][j];
      for (int k = 2; k <= m; k++) tmp = min(tmp, abs(a[i][k] - a[j][k - 1]));
      res = max(res, tmp);
    }
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Enter();
  Init();
  Solve();
  return 0;
}
