#include <bits/stdc++.h>
using namespace std;
long long N, M, rsp, pri;
long long a[20][10005];
long long cst[20][20];
long long sp[20][20];
bool vis[70000][20];
long long memo[70000][20];
long long dfs(long long msk, long long pas) {
  if (vis[msk][pas]) return memo[msk][pas];
  if (msk == (1 << N) - 1) return sp[pas][pri];
  long long ans = 0;
  for (int i = 1; i <= N; i++)
    if (!(msk & 1 << (i - 1)))
      ans = max(ans, min(cst[pas][i], dfs(msk | (1 << (i - 1)), i)));
  vis[msk][pas] = 1;
  return memo[msk][pas] = ans;
}
long long doSp(long long b, long long c) {
  long long ans = 1e15;
  for (long long j = 1; j < M; j++) ans = min(ans, abs(a[b][j] - a[c][j + 1]));
  return ans;
}
long long doCst(long long b, long long c) {
  long long ans = 1e15;
  for (long long j = 1; j <= M; j++) ans = min(ans, abs(a[b][j] - a[c][j]));
  return ans;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  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 = 1e15;
    for (long long i = 2; i <= M; i++)
      ans = min(ans, abs(a[1][i - 1] - a[1][i]));
    cout << ans;
    return 0;
  }
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= N; j++)
      if (i != j) {
        cst[i][j] = doCst(i, j);
        sp[i][j] = doSp(i, j);
      }
  for (long long i = 1; i <= N; i++) {
    pri = i;
    memset(vis, 0, sizeof vis);
    rsp = max(rsp, dfs((1 << (i - 1)), i));
  }
  cout << rsp;
  return 0;
}
