#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  if (n == 1) {
    int res = 2e9;
    for (int i = 1; i < m; i++) {
      res = min(res, abs(a[0][i] - a[0][i - 1]));
    }
    cout << res;
    return 0;
  }
  vector<vector<int>> d1(n, vector<int>(n, 2e9));
  vector<vector<int>> d2(n, vector<int>(n, 2e9));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      for (int t = 0; t < m; t++) {
        d1[i][j] = min(d1[i][j], abs(a[i][t] - a[j][t]));
      }
      for (int t = 1; t < m; t++) {
        d2[i][j] = min(d2[i][j], abs(a[i][t] - a[j][t - 1]));
      }
    }
  }
  int k = 0;
  for (int i = 0; i < n; i++) {
    int all_vert = 1 << n;
    int curr_vert = 1 << i;
    vector<vector<int>> dp(all_vert, vector<int>(n, -2e9));
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      dp[(1 << j) | curr_vert][j] = d1[i][j];
    }
    for (int mask = curr_vert; mask < all_vert; mask++) {
      for (int j = 0; j < n; j++) {
        int end_vert = 1 << j;
        if ((mask & end_vert) == 0) continue;
        for (int q = 0; q < n; q++) {
          if (q == j) continue;
          dp[mask][j] = max(dp[mask][j], min(dp[mask ^ end_vert][q], d1[q][j]));
        }
      }
    }
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      dp[all_vert - 1][j] = min(dp[all_vert - 1][j], d2[i][j]);
      k = max(k, dp[all_vert - 1][j]);
    }
  }
  cout << k;
  return 0;
}
