#include <bits/stdc++.h>
using namespace std;
void PV(vector<int> v) {
  for (int i = 0; i < (int)v.size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void PVV(vector<pair<int, int> > v) {
  for (int i = 0; i < (int)v.size(); i++)
    cout << v[i].first << " " << v[i].second << "\n";
}
void PA(int v[], int n, int x = 0) {
  for (int i = x; i < n + x; i++) cout << v[i] << ' ';
  cout << "\n";
}
void IN(int a[], int n, int x = 0) {
  for (int i = x; i < n + x; i++) cin >> a[i];
}
inline void op() {}
const int M = 1e9 + 7;
const int IM = 1e9 + 37;
const int N = 2e4 + 10;
int a[20][N];
int b[20][20], c[20][20];
int dp[(1ll << 17)][20][20];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  op();
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  fill(*b, *b + 20 * 20, IM);
  fill(*c, *c + 20 * 20, IM);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++)
        b[i][j] = min(b[i][j], abs(a[i][k] - a[j][k]));
      for (int k = 0; k + 1 < m; k++)
        c[i][j] = min(c[i][j], abs(a[i][k] - a[j][k + 1]));
    }
  }
  for (int i = 0; i < n; i++) dp[(1ll << i)][i][i] = IM;
  int ans = 0;
  for (int mask = 1; mask < (1ll << n); mask++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        int cn = __builtin_popcount(mask);
        if (cn == n) {
          ans = max(ans, min(dp[mask][i][j], c[i][j]));
          continue;
        }
        if (cn == 1 || (i != j)) {
          if (mask & (1ll << i)) {
            if (mask & (1ll << j)) {
              for (int k = 0; k < n; k++) {
                if ((mask & (1ll << k))) continue;
                int cost = min(b[j][k], dp[mask][i][j]);
                dp[mask | (1ll << k)][i][k] =
                    max(dp[mask | (1ll << k)][i][k], cost);
              }
            }
          }
        }
      }
    }
  }
  cout << (ans) << "\n";
  return 0;
}
