#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int n, cst[20][20], cstE[20][20];
int res[20][70000];
int F;
int dp(int p, int bm) {
  if (!bm) return cstE[F][p];
  if (res[p][bm] != -1) return res[p][bm];
  vector<int> d;
  for (int i = 0; i < n; i++) {
    if ((1 << i) & bm) d.push_back(i);
  }
  int w = 0;
  for (int x : d) w = max(w, min(cst[p][x], dp(x, bm ^ (1 << x))));
  return res[p][bm] = w;
}
int M[20][70000];
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) scanf("%d", &M[i][j]);
  }
  for (int u = 0; u < n; u++) {
    for (int v = 0; v < n; v++) {
      if (u == v) continue;
      int mn = (1 << 30);
      for (int j = 0; j < m; j++) mn = min(mn, abs(M[u][j] - M[v][j]));
      cst[u][v] = mn;
    }
  }
  for (int u = 0; u < n; u++) {
    for (int v = 0; v < n; v++) {
      int mn = (1 << 30);
      for (int j = 1; j < m; j++) mn = min(mn, abs(M[u][j] - M[v][j - 1]));
      cstE[u][v] = mn;
    }
  }
  int ans = 0;
  for (F = 0; F < n; F++) {
    memset(res, -1, sizeof(res));
    ans = max(ans, dp(F, ((1 << n) - 1) ^ (1 << F)));
  }
  cout << ans << endl;
}
