#include <bits/stdc++.h>
using namespace std;
int total, row;
int arr[18][10010];
int dp[18][18][1 << 17];
int arr1[18][18];
int arr2[18][18];
int calc(int start, int prev, int mask) {
  int ans = 0;
  int &res = dp[start][prev][mask];
  if (res != -1) return res;
  if (__builtin_popcount(mask) == total) return res = arr2[start][prev];
  for (int i = 0; i < total; i++) {
    if (mask & 1 << i) continue;
    int maxi = 1e18;
    if (!mask)
      ans = max(ans, calc(i, i, mask | 1 << i));
    else
      ans = max(ans, min(arr1[i][prev], calc(start, i, mask | 1 << i)));
  }
  return res = ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof dp);
  cin >> total >> row;
  for (int i = 0; i < total; i++) {
    for (int j = 0; j < row; j++) cin >> arr[i][j];
  }
  for (int i = 0; i < total; i++) {
    for (int j = 0; j < total; j++) {
      int maxi = 1e18;
      for (int k = 0; k < row; k++)
        maxi = min(maxi, abs(arr[i][k] - arr[j][k]));
      arr1[i][j] = maxi;
    }
  }
  for (int i = 0; i < total; i++) {
    for (int j = 0; j < total; j++) {
      int maxi = 1e18;
      for (int k = 0; k < row - 1; k++)
        maxi = min(maxi, abs(arr[i][k + 1] - arr[j][k]));
      arr2[i][j] = maxi;
    }
  }
  cout << calc(0, 0, 0) << endl;
}
