#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
vector<int> arr[20];
int n, m;
int edge[18][18];
int connect[18][18];
int dp[17][17][(1 << 17)];
int f(int a, int b, int state) {
  int& ret = dp[a][b][state];
  if (~ret) return ret;
  ret = 0;
  if (!state) return ret = edge[a][b];
  for (int i = 0; i < n; i++) {
    if (state & (1 << i)) {
      ret = max(ret, min(edge[a][i], f(i, b, state ^ (1 << i))));
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int a;
      cin >> a;
      arr[i].push_back(a);
    }
  }
  if (n == 1) {
    int ans = INT32_MAX;
    for (int j = 1; j < m; j++) ans = min(ans, abs(arr[0][j - 1] - arr[0][j]));
    cout << ans;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      int mindiff = INT32_MAX;
      for (int k = 0; k < m; k++) {
        mindiff = min(mindiff, abs(arr[i][k] - arr[j][k]));
      }
      edge[i][j] = edge[j][i] = mindiff;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      int mindiff = INT32_MAX;
      for (int k = 1; k < m; k++) {
        mindiff = min(mindiff, abs(arr[i][k] - arr[j][k - 1]));
      }
      connect[i][j] = mindiff;
    }
  }
  memset(dp, -1, sizeof(dp));
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      int state = (1 << n) - 1;
      state ^= (1 << i);
      state ^= (1 << j);
      ans = max(ans, min(connect[i][j], f(i, j, state)));
    }
  }
  cout << ans;
}
