#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const double eps = 1e-10;
const long long N = 1e4 + 7;
const long long MOD = 1e9 + 7;
long long pw(long long b, long long p) {
  long long res = 1;
  while (p > 0) {
    if (p & 1) res = res * b;
    b = b * b;
    p >>= 1;
  }
  return res;
}
long long n, m;
long long dp[16][16][1LL << 16];
long long a[16][N];
long long g1[16][16], g2[16][16];
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      long long mn = 0x3f3f3f3f3f3f3f3fLL;
      for (long long k = 0; k < m; k++) {
        mn = min(mn, abs(a[i][k] - a[j][k]));
      }
      g1[i][j] = mn;
      mn = 0x3f3f3f3f3f3f3f3fLL;
      for (long long k = 0; k < m - 1; k++) {
        mn = min(mn, abs(a[i][k] - a[j][k + 1]));
      }
      g2[i][j] = mn;
    }
  }
  for (long long i = 0; i < n; i++) {
    dp[i][i][1LL << i] = 0x3f3f3f3f3f3f3f3fLL;
  }
  for (long long mask = 1; mask < (1LL << n); mask++) {
    for (long long start = 0; start < n; start++) {
      if ((mask >> start) & 1) {
        for (long long mid = 0; mid < n; mid++) {
          if ((mask >> mid) & 1) {
            for (long long to = 0; to < n; to++) {
              if (!((mask >> to) & 1)) {
                dp[start][to][mask | (1LL << to)] =
                    max(dp[start][to][mask | (1LL << to)],
                        min(dp[start][mid][mask], g1[mid][to]));
              }
            }
          }
        }
      }
    }
  }
  long long mask = (1LL << n) - 1;
  long long ans = 0;
  for (long long start = 0; start < n; start++) {
    for (long long to = 0; to < n; to++) {
      ans = max(ans, min(dp[start][to][mask], g2[to][start]));
    }
  }
  cout << ans;
  return 0;
}
