#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[21][10001];
int c[21][21];
int d[21][21];
int dp[21][1 << 16];
int s = 0;
int d__p(int i, int mask) {
  if (mask == (1 << n) - 1) {
    return d[s][i];
  }
  int &res = dp[i][mask];
  if (res != -1) return res;
  res = 0;
  for (int v = 0; v < n; v++) {
    if (mask & (1 << v)) continue;
    res = max(res, min(d__p(v + 1, mask | 1 << v), c[i][v + 1]));
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int Min = 2e9;
      for (int k = 1; k <= m; k++) {
        Min = min(Min, abs(a[i][k] - a[j][k]));
      }
      c[i][j] = Min;
      Min = 2e9;
      for (int k = 1; k < m; k++) {
        Min = min(Min, abs(a[j][k] - a[i][k + 1]));
      }
      d[i][j] = Min;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    s = i;
    memset(dp, -1, sizeof dp);
    ans = max(ans, d__p(i, 1 << (i - 1)));
  }
  cout << ans;
  return 0;
}
