#include <bits/stdc++.h>
using namespace std;
int dp[17][17][200000];
int n, m;
int a[17][10005], dist[17][17], dist2[17][17];
int f(int start, int now, int mask, int cnt) {
  if (dp[start][now][mask] != -1) return dp[start][now][mask];
  if (cnt == n) return 1e9;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (mask & (1 << i)) continue;
    int d = min(dist[now][i], f(start, i, mask | (1 << i), cnt + 1));
    if (cnt + 1 == n) d = min(d, dist2[start][i]);
    ans = max(ans, d);
  }
  dp[start][now][mask] = ans;
  return ans;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int ans;
  if (n == 1) {
    ans = 1e9;
    for (int j = 1; j < m; j++) {
      ans = min(ans, abs(a[0][j] - a[0][j - 1]));
    }
  } else {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dist[i][j] = abs(a[i][0] - a[j][0]);
        dist2[i][j] = 1e9;
        for (int k = 1; k < m; k++) {
          dist[i][j] = min(dist[i][j], abs(a[i][k] - a[j][k]));
          dist2[i][j] = min(dist2[i][j], abs(a[i][k] - a[j][k - 1]));
        }
      }
    }
    memset(dp, -1, sizeof(dp));
    ans = 0;
    for (int i = 0; i < n; i++) {
      ans = max(ans, f(i, i, 1 << i, 1));
    }
  }
  printf("%d\n", ans);
}
