#include <bits/stdc++.h>
using namespace std;
long long dp[100005][16][17] = {{{0}}};
long long is[20][20];
vector<vector<long long>> a;
int n, m;
long long cal(int bits, int s, int e) {
  if (dp[bits][s][e] != -1) return dp[bits][s][e];
  if (bits == 0) {
    long long x = 100000000000;
    for (int j = 0; j < m - 1; j++) {
      x = min(abs(a[e][j] - a[s][j + 1]), x);
    }
    return dp[bits][s][e] = x;
  }
  long long x = 0;
  for (int i = 0; i < n; i++) {
    if ((bits & (1 << i)) != 0) {
      x = max(min(cal((bits ^ (1 << i)), s, i), is[e][i]), x);
    }
  }
  return dp[bits][s][e] = x;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  memset(dp, -1, sizeof dp);
  a = vector<vector<long long>>(n);
  for (int i = 0; i < n; i++) a[i] = vector<long long>(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++) {
      is[i][j] = abs(a[i][0] - a[j][0]);
      for (int z = 0; z < m; z++) {
        is[i][j] = min(is[i][j], abs(a[i][z] - a[j][z]));
      }
    }
  }
  long long x = 0;
  int bits = (1 << n) - 1;
  for (int i = 0; i < n; i++) {
    x = max(x, cal((bits ^ (1 << i)), i, i));
  }
  cout << x << '\n';
  return 0;
}
