#include <bits/stdc++.h>
using namespace std;
const int MaxN = 16;
const int MaxM = 10005;
const int Inf = 0x3f3f3f3f;
int N, M;
int a[MaxN][MaxM];
int maxDif[MaxN][MaxN];
int D[1 << MaxN][MaxN];
void ReadData();
void Calc_maxDif();
int Dyn(int p);
int Mod(int a);
int main() {
  ReadData();
  Calc_maxDif();
  int res{0};
  for (int i = 0; i < N; ++i) res = max(res, Dyn(i));
  cout << res;
  return 0;
}
void ReadData() {
  cin >> N >> M;
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j) cin >> a[i][j];
}
void Calc_maxDif() {
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < N; ++j) {
      if (i == j) continue;
      int dmax{Inf};
      for (int k = 0; k < M; ++k) dmax = min(dmax, Mod(a[i][k] - a[j][k]));
      maxDif[i][j] = maxDif[j][i] = dmax;
    }
}
int Dyn(int p) {
  for (int mask = 0; mask < (1 << N); ++mask)
    for (int i = 0; i < N; ++i) D[mask][i] = 0;
  D[1 << p][p] = Inf;
  for (int mask = 1; mask < (1 << N); ++mask)
    for (int i = 0; i < N; ++i) {
      if (!(mask & (1 << i)) || !(mask & (1 << p)) || i == p) continue;
      for (int j = 0; j < N; ++j)
        if (i != j && (mask & (1 << j))) {
          D[mask][i] =
              max(D[mask][i], min(D[mask ^ (1 << i)][j], maxDif[i][j]));
        }
    }
  int res{0};
  for (int i = 0; i < N; ++i) {
    int dif{Inf};
    for (int j = 0; j < M - 1; ++j) dif = min(dif, Mod(a[i][j] - a[p][j + 1]));
    res = max(res, min(D[(1 << N) - 1][i], dif));
  }
  return res;
}
int Mod(int a) { return a >= 0 ? a : -a; }
