#include <bits/stdc++.h>
using namespace std;
const long long N = 17;
const long long M = 1e4 + 5;
long long n, m;
long long a[N][M], store[N][N], store2[N][N];
long long cache[N][1 << (N - 1)][N];
long long dp(long long start, long long mask, long long prev) {
  if ((mask + 1) == (1 << n)) return 1e9;
  long long &ans = cache[start][mask][prev];
  if (ans != -1) return ans;
  ans = 0;
  long long cnt = __builtin_popcount(mask);
  for (long long i = 0; i < n; i++) {
    if (mask >> i & 1) continue;
    long long prv = prev + 1;
    long long nxt = i + 1;
    long long cur = min(store[prv][nxt], dp(start, mask | (1 << i), i));
    if (cnt == n - 1) cur = min(cur, store2[start + 1][nxt]);
    ans = max(ans, cur);
  }
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  memset(cache, -1, sizeof(cache));
  cin >> n >> m;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) cin >> a[i][j];
  if (n == 1) {
    long long ans = 1e9;
    for (long long i = 1; i <= m - 1; i++)
      ans = min(ans, abs(a[1][i] - a[1][i + 1]));
    cout << ans;
    return 0;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      store[i][j] = 1e9;
      if (i == j) continue;
      for (long long k = 1; k <= m; k++)
        store[i][j] = min(store[i][j], abs(a[i][k] - a[j][k]));
    }
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      store2[i][j] = 1e9;
      if (i == j) continue;
      for (long long k = 1; k <= m - 1; k++)
        store2[i][j] = min(store2[i][j], abs(a[i][k] - a[j][k + 1]));
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) ans = max(ans, dp(i, (1 << i), i));
  cout << ans;
  return 0;
}
