#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int INF = 1e9 + 7;
int m, n, ans = 0, b[17], a[17][10005], f[1 << 16 | 1][17], C[17][17];
inline int cal(const int &x, const int &y) {
  int ret = INF;
  for (int j = 1; j <= n; j++) ret = min(ret, abs(a[x][j] - a[y][j]));
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> m >> n;
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++) cin >> a[i][j];
  if (m == 1) {
    int t = INF;
    for (int j = 1; j < n; j++) t = min(t, abs(a[1][j] - a[1][j + 1]));
    cout << t;
    exit(0);
  }
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= m; j++) C[i][j] = cal(i, j);
  for (int x1 = 1; x1 <= m; x1++)
    for (int x2 = 1; x2 <= m; x2++)
      if (x1 != x2) {
        int sz = 0;
        for (int i = 1; i <= m; i++)
          if (i != x1 && i != x2) b[++sz] = i;
        for (int mask = 0; mask < 1 << sz; mask++)
          for (int i = 0; i < sz; i++) f[mask][i] = INF;
        for (int mask = 0; mask < 1 << sz; mask++) {
          for (int i = 0; i < sz; i++)
            if (mask >> i & 1) {
              if (__builtin_popcount(mask) == 1) {
                f[mask][i] = C[b[i + 1]][x1];
              } else {
                f[mask][i] = 0;
                int preMask = mask ^ (1 << i);
                for (int j = 0; j < sz; j++)
                  if (preMask >> j & 1)
                    f[mask][i] = max(f[mask][i],
                                     min(f[preMask][j], C[b[i + 1]][b[j + 1]]));
              }
            }
        }
        int t = INF;
        for (int j = 1; j < n; j++) t = min(t, abs(a[x2][j] - a[x1][j + 1]));
        for (int i = 0; i < sz; i++)
          ans = max(ans, min({t, f[(1 << sz) - 1][i], C[b[i + 1]][x2]}));
        if (sz == 0) ans = max(ans, min({t, C[x1][x2]}));
      }
  cout << ans;
  return 0;
}
