#include <bits/stdc++.h>
using namespace std;
int arr[20][20];
int dp[(1 << 16) + 5][20][20];
int n, m;
vector<vector<int> > vt;
int pre[20][20];
int calc(vector<int> a, vector<int> b) {
  int mn = (int)1e9 + 7;
  for (int i = 0; i < a.size(); i++) {
    int x = abs(a[i] - b[i]);
    mn = min(mn, x);
  }
  return mn;
}
int f(vector<int> first, vector<int> last) {
  int mn = 1 << 30;
  for (int i = 0; i < last.size() - 1; i++) {
    int x = abs(last[i] - first[i + 1]);
    mn = min(mn, x);
  }
  return mn;
}
int solve(int mask, int first, int prev) {
  if (__builtin_popcount(mask) == n) {
    return f(vt[first], vt[prev]);
  }
  if (dp[mask][first][prev] != -1) {
    return dp[mask][first][prev];
  }
  int ret = -1000000;
  if (mask == 0) {
    for (int i = 0; i < n; i++) {
      ret = max(ret, solve(mask | (1 << i), i, i));
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (mask & (1 << i)) {
        continue;
      }
      ret = max(ret, min(arr[i][prev], solve(mask | (1 << i), first, i)));
    }
  }
  return dp[mask][first][prev] = ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    vector<int> temp;
    int x;
    for (int j = 0; j < m; j++) {
      cin >> x;
      temp.push_back(x);
    }
    vt.push_back(temp);
  }
  for (int i = 0; i < vt.size(); i++) {
    for (int j = 0; j < vt.size(); j++) {
      if (i == j) {
        arr[i][j] = 1 << 27;
        continue;
      }
      arr[i][j] = calc(vt[i], vt[j]);
    }
  }
  for (int i = 0; i < vt.size(); i++) {
    for (int j = 0; j < vt.size(); j++) {
      pre[i][j] = f(vt[i], vt[j]);
    }
  }
  memset(dp, -1, sizeof(dp));
  int ans = solve(0, 0, 0);
  cout << ans << endl;
  return 0;
}
