#include <bits/stdc++.h>
const long long Inf = 1e18;
long long LINF = (long long)2e18;
using namespace std;
long long mod = 1e9 + 7;
long long mod3 = 998244353;
long long mod2 = 1e9 + 123;
int n, m;
vector<vector<long long>> a;
vector<vector<long long>> mn_diff(16, vector<long long>(16, Inf));
vector<vector<long long>> mn_diff2(16, vector<long long>(16, Inf));
long long dp[66000][16][16];
long long kek;
long long rec(bitset<16> used, int last, int fi) {
  int abc = used.to_ullong();
  if (used.to_ullong() == kek) return Inf;
  if (dp[used.to_ullong()][last][fi] != -1)
    return dp[used.to_ullong()][last][fi];
  long long ans = 0;
  for (int(i) = 0; (i) < n; (i)++) {
    if (!used[i]) {
      used[i] = 1;
      if (used.to_ullong() == kek) {
        ans = max(ans,
                  min({rec(used, i, fi), mn_diff[last][i], mn_diff2[i][fi]}));
      } else {
        ans = max(ans, min(rec(used, i, fi), mn_diff[last][i]));
      }
      used[i] = 0;
    }
  }
  return dp[used.to_ullong()][last][fi] = ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  a.resize(n, vector<long long>(m));
  for (int(i) = 0; (i) < n; (i)++) {
    for (int(j) = 0; (j) < m; (j)++) {
      cin >> a[i][j];
    }
  }
  kek = (1 << n) - 1;
  for (int(i) = 0; (i) < n; (i)++) {
    for (int(j) = 0; (j) < n; (j)++) {
      long long mn = Inf;
      for (int(k) = 0; (k) < m; (k)++) {
        mn = min(mn, abs(a[i][k] - a[j][k]));
      }
      mn_diff[i][j] = mn;
    }
  }
  for (int(i) = 0; (i) < n; (i)++) {
    for (int(j) = 0; (j) < n; (j)++) {
      long long mn = Inf;
      for (int(k) = 1; (k) < m; (k)++) {
        mn = min(mn, abs(a[i][k - 1] - a[j][k]));
      }
      mn_diff2[i][j] = mn;
    }
  }
  if (n == 1) {
    cout << mn_diff2[0][0];
    return 0;
  }
  long long ans = 0;
  memset(dp, -1, sizeof(dp));
  bitset<16> lol = 0;
  for (int(i) = 0; (i) < n; (i)++) {
    lol[i] = 1;
    ans = max(ans, rec(lol, i, i));
    lol[i] = 0;
  }
  cout << ans;
  return 0;
}
