#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
bool ispoweroftwo(long long n) { return n & (!(n & (n - 1))); }
long long mod = 1000000007;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, -1, 0, 1};
bool test = 0;
const long long inf = 1e9;
const long long N = 16;
long long m, n;
long long adj_row[N][N];
long long top_bottom_row[N][N];
long long mat[N][10000];
long long cache[N][N][1LL << N];
long long dp(long long start_row, long long prev_row, long long mask) {
  if (mask == (1LL << n) - 1) return 1e9;
  long long &ans = cache[start_row][prev_row][mask];
  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 cur = inf;
    if (cnt == n - 1) cur = top_bottom_row[start_row][i];
    cur = min({cur, adj_row[prev_row][i], dp(start_row, i, mask | (1LL << i))});
    ans = max(ans, cur);
  }
  return ans;
}
void solve(long long tc = 0) {
  cin >> n >> m;
  for (long long i = 0; i < n; ++i)
    for (long long j = 0; j < m; ++j) cin >> mat[i][j];
  if (n == 1) {
    long long ans = inf;
    for (long long i = 0; i < m - 1; ++i)
      ans = min(ans, abs(mat[0][i] - mat[0][i + 1]));
    cout << ans << "\n";
    return;
  }
  for (long long i = 0; i < n; ++i) {
    for (long long j = i + 1; j < n; ++j) {
      adj_row[i][j] = inf;
      top_bottom_row[i][j] = inf;
      top_bottom_row[j][i] = inf;
      for (long long k = 0; k < m; ++k) {
        adj_row[i][j] = min(adj_row[i][j], abs(mat[i][k] - mat[j][k]));
        if (k == m - 1) continue;
        top_bottom_row[i][j] =
            min(top_bottom_row[i][j], abs(mat[i][k] - mat[j][k + 1]));
        top_bottom_row[j][i] =
            min(top_bottom_row[j][i], abs(mat[j][k] - mat[i][k + 1]));
      }
      adj_row[j][i] = adj_row[i][j];
    }
  }
  memset(cache, -1, sizeof(cache));
  long long ans = 0;
  for (long long i = 0; i < n; ++i) ans = max(ans, dp(i, i, 1LL << i));
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  if (test) cin >> t;
  for (long long i = 1; i <= t; ++i) {
    solve(i);
  }
  return 0;
}
