#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int nax = 17;
const int inf = 2e9;
const int M = 1e4 + 6;
const long long INF = 2e18;
int n, m, a[nax][M], trans[nax][nax], ptrans[nax][nax];
int dp[1 << nax][nax][nax];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      trans[i][j] = inf;
      for (int k = 0; k < m; k++) {
        trans[i][j] = min(trans[i][j], abs(a[i][k] - a[j][k]));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ptrans[i][j] = inf;
      for (int k = 0; k < m - 1; k++) {
        ptrans[i][j] = min(ptrans[i][j], abs(a[i][k] - a[j][k + 1]));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    dp[1 << i][i][i] = inf;
  }
  for (int mask = 1; mask < (1 << n) - 1; mask++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (__builtin_popcount(mask) > 1 && i == j) {
          continue;
        }
        if ((mask & (1 << i)) && (mask & (1 << j))) {
          for (int new_row = 0; new_row < n; new_row++) {
            if (!(mask & (1 << new_row))) {
              int new_mask = mask ^ (1 << new_row);
              int move = min(dp[mask][i][j], trans[j][new_row]);
              dp[new_mask][i][new_row] = max(dp[new_mask][i][new_row], move);
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      ans = max(ans, min(dp[(1 << n) - 1][i][j], ptrans[i][j]));
    }
  }
  cout << ans << '\n';
  return 0;
}
