#include <bits/stdc++.h>
using namespace std;
const int N = 18;
const int M = 100 * 1000 + 13;
const int INF = 1e9;
int dp[1 << N][N];
int dist[N][N], dist2[N][N];
int a[N][M];
int n, m, i, j;
int calc(int mask, int u) {
  if (dp[mask][u] != -1) {
    return dp[mask][u];
  }
  dp[mask][u] = 0;
  for (int i = 0; i < n; i++) {
    if (u != i && ((mask >> i) & 1)) {
      dp[mask][u] = max(dp[mask][u], min(calc(mask ^ (1 << u), i), dist[i][u]));
    }
  }
  return dp[mask][u];
}
int main() {
  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++) {
      dist[i][j] = INF;
      dist2[i][j] = INF;
      for (int k = 0; k < m; k++) {
        dist[i][j] = min(dist[i][j], abs(a[i][k] - a[j][k]));
      }
      for (int k = 1; k < m; k++) {
        dist2[i][j] = min(dist2[i][j], abs(a[i][k] - a[j][k - 1]));
      }
    }
  }
  int t = (1 << n) - 1;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    memset(dp, -1, sizeof(dp));
    for (int j = 0; j < n; j++) {
      dp[1 << j][j] = 0;
    }
    dp[1 << i][i] = INF;
    for (int j = 0; j < n; j++) {
      ans = max(ans, min(dist2[j][i], calc(t, j)));
    }
  }
  cout << ans << endl;
  return 0;
}
