#include <bits/stdc++.h>
using namespace std;
const int N = 17;
const int M = 1e4 + 4;
const int INF = 2e9;
int dp[N][1 << N][N], n, m;
int a[N][M], val1[N][N], val2[N][N];
int go(int cur, int mask, int prv) {
  if (mask == (1 << n) - 1) return INF;
  int &ans = dp[cur][mask][prv];
  if (ans != -1) return ans;
  ans = 0;
  for (int i = 0; i < n; i++) {
    if (mask & (1 << i)) continue;
    int res = min(val1[prv][i], go(cur, mask | (1 << i), i));
    if ((mask | (1 << i)) == (1 << n) - 1) res = min(res, val2[i][cur]);
    ans = max(ans, res);
  }
  return ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) val2[i][j] = val1[i][j] = INF;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  if (n == 1) {
    int ans = INF;
    for (int i = 0; i < m - 1; i++) ans = min(ans, abs(a[0][i] - a[0][i + 1]));
    return cout << ans << "\n", 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        val1[i][j] = min(val1[i][j], abs(a[i][k] - a[j][k]));
        if (k < m - 1) val2[i][j] = min(val2[i][j], abs(a[i][k] - a[j][k + 1]));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) ans = max(ans, go(i, 1 << i, i));
  cout << ans << "\n";
}
