#include <bits/stdc++.h>
using namespace std;
const long long MOD = (1e9 + 7);
const long long INF = (1e9 + 123456789);
const long long INFL = (INF * INF);
inline long long addm(long long a, long long b, long long m = MOD) {
  return ((a + b) % m);
}
inline long long subm(long long a, long long b, long long m = MOD) {
  return (((a - b) % m + m) % m);
}
inline long long mulm(long long a, long long b, long long m = MOD) {
  return ((a * b) % m);
}
long long powm(long long a, long long b, long long m = MOD) {
  long long ret = (!b) ? 1 : powm(a, b / 2);
  return (!b) ? 1 : mulm(mulm(ret, ret, m), b % 2 ? a : 1, m);
}
long long gcd(long long a, long long b) { return (!b) ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long inv(long long x, long long m = MOD) { return powm(x, m - 2, m); }
int n, m;
int a[18][10500];
int vis[18][1 << 18];
int cost[18][18], shift[18][18];
set<pair<int, int> > mask[1 << 18];
bool can(int k) {
  for (int i = 0; i < n; i++) {
    queue<pair<int, int> > q;
    q.push({i, (1 << i)});
    memset(vis, 0, sizeof(vis));
    vis[i][(1 << i)] = true;
    while (!q.empty()) {
      int v, used;
      tie(v, used) = q.front();
      q.pop();
      if (used == ((1 << n) - 1)) {
        if (shift[v][i] >= k) return true;
        continue;
      }
      for (int u = 0; u < n; u++) {
        if (used & (1 << u)) continue;
        int nu = used | (1 << u);
        if (vis[u][nu]) continue;
        if (cost[v][u] < k) continue;
        vis[u][nu] = true;
        q.push({u, nu});
      }
    }
  }
  return false;
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> a[i][j];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      cost[i][j] = INF;
      for (int k = 0; k < m; k++)
        cost[i][j] = min(cost[i][j], abs(a[i][k] - a[j][k]));
    }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      shift[i][j] = INF;
      for (int k = 0; k + 1 < m; k++)
        shift[i][j] = min(shift[i][j], abs(a[i][k] - a[j][k + 1]));
    }
  if (n == 1) {
    int mn = INF;
    for (int j = 0; j + 1 < m; j++) mn = min(mn, abs(a[0][j] - a[0][j + 1]));
    cout << mn << "\n";
    return;
  }
  long long l = 0, r = INF;
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (can(mid))
      l = mid;
    else
      r = mid;
  }
  cout << l << "\n";
}
int main(int argc, char *argv[]) {
  cin.sync_with_stdio(0);
  cin.tie(NULL);
  solve();
  return 0;
}
