#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
using namespace std;
mt19937_64 gen(time(NULL));
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long a[16][10000];
long long dp[16][16][1LL << 17 - 1];
long long x[16][16];
long long y[16][16];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) cin >> a[i][j];
  if (n == 1) {
    long long rofl = LLONG_MAX;
    for (long long i = 0; i < m - 1; i++) {
      rofl = min(rofl, abs(a[0][i] - a[0][i + 1]));
    }
    cout << rofl << endl;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      if (i == j) continue;
      long long kek = LLONG_MAX;
      for (long long k = 0; k < m; k++) {
        kek = min(kek, abs(a[i][k] - a[j][k]));
      }
      x[i][j] = kek;
      kek = LLONG_MAX;
      for (long long k = 0; k < m - 1; k++) {
        kek = min(kek, abs(a[i][k] - a[j][k + 1]));
      }
      y[i][j] = kek;
    }
  }
  for (long long beg = 0; beg < n; beg++) {
    for (long long end = 0; end < n; end++) {
      if (beg == end) continue;
      long long mask = (1LL << beg) | (1LL << end);
      dp[beg][end][mask] = x[beg][end];
    }
  }
  for (long long mask = 0; mask < 1LL << (n); mask++) {
    for (long long beg = 0; beg < n; beg++) {
      for (long long end = 0; end < n; end++) {
        if ((((1LL << beg) & mask) == 0) || (((1LL << end) & mask) == 0))
          continue;
        if (beg == end) continue;
        for (long long old_end = 0; old_end < n; old_end++) {
          if (((1LL << old_end) & mask) == 0) continue;
          if (old_end == end) continue;
          dp[beg][end][mask] =
              max(dp[beg][end][mask],
                  min(x[old_end][end], dp[beg][old_end][mask ^ (1LL << end)]));
        }
      }
    }
  }
  long long ans = 0;
  for (long long beg = 0; beg < n; beg++) {
    for (long long end = 0; end < n; end++) {
      if (beg == end) continue;
      long long mask = (1LL << (n)) - 1;
      ans = max(ans, min(dp[beg][end][mask], y[beg][end]));
    }
  }
  cout << ans << endl;
  return 0;
}
