#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, m, a[16][11234], b[16][16], c[16][16], dp[1 << 16][16];
void solve(int u) {
  for (int i = 0; i < 1 << n; ++i)
    for (int j = 0; j < n; ++j) dp[i][j] = 0;
  dp[1 << u][u] = inf;
  for (int i = 0; i < 1 << n; ++i)
    for (int j = 0; j < n; ++j)
      if (dp[i][j])
        for (int k = 0; k < n; ++k)
          if (!(i >> k & 1))
            dp[i | (1 << k)][k] =
                max(dp[i | (1 << k)][k], min(dp[i][j], b[j][k]));
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) scanf("%d", &a[i][j]);
  if (n == 1) {
    int res = inf;
    for (int j = 0; j < m - 1; ++j) res = min(res, abs(a[0][j] - a[0][j + 1]));
    printf("%d\n", res);
    return 0;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (i != j) {
        b[i][j] = c[i][j] = inf;
        for (int k = 0; k < m; ++k)
          b[i][j] = min(b[i][j], abs(a[i][k] - a[j][k]));
        for (int k = 0; k < m - 1; ++k)
          c[i][j] = min(c[i][j], abs(a[i][k] - a[j][k + 1]));
      }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    solve(i);
    for (int j = 0; j < n; ++j)
      if (i != j) res = max(res, min(c[i][j], dp[(1 << n) - 1][j]));
  }
  cout << res << endl;
  return 0;
}
