#include <bits/stdc++.h>
using namespace std;
function<void(void)> ____ = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
const int MAXN = 1e4 + 7;
int n, m, A[16][MAXN], dta[16][16], dtb[16][16], f[16][16][1 << 16];
int main() {
  ____();
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> A[i][j];
  memset(dta, 0x3f, sizeof(dta));
  memset(dtb, 0x3f, sizeof(dtb));
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++)
        dta[i][j] = min(dta[i][j], abs(A[i][k] - A[j][k]));
      for (int k = 0; k < m - 1; k++)
        dtb[i][j] = min(dtb[i][j], abs(A[i][k] - A[j][k + 1]));
    }
  if (n == 1) {
    cout << dtb[0][0] << endl;
    return 0;
  }
  memset(f, 0, sizeof(f));
  for (int msk = 1; msk < (1 << n); msk++) {
    if (__builtin_popcount(msk) == 1)
      f[__builtin_ctz(msk)][__builtin_ctz(msk)][msk] = 0x3f3f3f3f;
    for (int i = 0; i < n; i++) {
      if (msk & (1 << i)) continue;
      for (int j = 0; j < n; j++) {
        if (!(msk & (1 << j))) continue;
        for (int k = 0; k < n; k++) {
          if (!(msk & (1 << k))) continue;
          f[j][i][msk | (1 << i)] =
              max(f[j][i][msk | (1 << i)], min(f[j][k][msk], dta[k][i]));
        }
      }
    }
  }
  int maxx = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      f[i][j][(1 << n) - 1] = min(f[i][j][(1 << n) - 1], dtb[j][i]);
      maxx = max(maxx, f[i][j][(1 << n) - 1]);
    }
  cout << maxx << endl;
  return 0;
}
