#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 9, inf = 1e18, mod = 1e9 + 7;
long long ar[17][10009], dp[65600][17][17], n, m;
long long pre[17][17], pospre[17][17];
long long maximize(long long msk, long long prv, long long fst) {
  if (__builtin_popcount(msk) == n) return pospre[prv][fst];
  if (~dp[msk][prv][fst]) return dp[msk][prv][fst];
  long long mx = -1;
  for (long long i = 0; i < n; i++) {
    if ((msk & (1LL << i)) == 0) {
      long long x = maximize((msk | (1LL << i)), i, fst);
      x = min(x, pre[prv][i]);
      mx = max(mx, x);
    }
  }
  return dp[msk][prv][fst] = mx;
}
void precal() {
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      pre[i][j] = inf;
      pospre[i][j] = inf;
      for (long long k = 1; k <= m; k++) {
        pre[i][j] = min(pre[i][j], abs(ar[i][k] - ar[j][k]));
        if (k < m)
          pospre[i][j] = min(pospre[i][j], abs(ar[i][k] - ar[j][k + 1]));
      }
    }
  }
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> m;
  long long mx = -inf;
  for (long long i = 0; i < n; i++)
    for (long long j = 1; j <= m; j++) cin >> ar[i][j];
  precal();
  for (long long i = 0; i < n; i++) {
    mx = max(mx, maximize((1LL << i), i, i));
  }
  cout << mx << "\n";
  return 0;
}
