#include <bits/stdc++.h>
using namespace std;
const int N = 200500;
int n, m;
int a[32][N];
int esp[32][32];
int x[32][32];
int dp[1 << 16][16];
int f(int mask, int last, int init) {
  if (mask == (1 << n) - 1) {
    return esp[last][init];
  }
  int &r = dp[mask][last];
  if (r != -1) return r;
  r = 0;
  for (int j = 0, qwerty = n; j < qwerty; j++) {
    if (!(mask & (1 << j))) {
      r = max(r, min(x[last][j], f(mask | (1 << j), j, init)));
    }
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0, qwerty = n; i < qwerty; i++)
    for (int j = 0, qwerty = m; j < qwerty; j++) cin >> a[i][j];
  if (n == 1) {
    int k = 2e9 + 10;
    for (int i = 0, qwerty = m - 1; i < qwerty; i++)
      k = min(k, abs(a[0][i] - a[0][i + 1]));
    cout << k << "\n";
    return 0;
  }
  for (int i = 0, qwerty = n; i < qwerty; i++) {
    for (int j = 0, qwerty = n; j < qwerty; j++) {
      if (i == j) continue;
      int k = 2e9 + 10;
      for (int h = 0, qwerty = m; h < qwerty; h++)
        k = min(k, abs(a[i][h] - a[j][h]));
      x[i][j] = k;
    }
  }
  for (int i = 0, qwerty = n; i < qwerty; i++) {
    for (int j = 0, qwerty = n; j < qwerty; j++) {
      if (i == j) continue;
      int k = 2e9 + 10;
      for (int h = 0, qwerty = m - 1; h < qwerty; h++)
        k = min(k, abs(a[i][h] - a[j][h + 1]));
      esp[i][j] = k;
    }
  }
  int r = 0;
  for (int i = 0, qwerty = n; i < qwerty; i++) {
    memset(dp, -1, sizeof dp);
    r = max(r, f(1 << i, i, i));
  }
  cout << r << "\n";
}
