#include <bits/stdc++.h>
const int INF = 1e+9, MAXN = 200005, HELL = 1e+9 + 7, MOD = 998244353;
const long long int INF64 = 1e+18;
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)), d1(n, vector<int>(n, INF)),
      d2(n, vector<int>(n, INF));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < m; ++k) {
        d1[i][j] = min(d1[i][j], abs(a[i][k] - a[j][k]));
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < m - 1; ++k) {
        d2[i][j] = min(d2[i][j], abs(a[i][k] - a[j][k + 1]));
      }
    }
  }
  int ans = 0;
  if (n > 1) {
    for (int start = 0; start < n; ++start) {
      vector<vector<int>> d(n, vector<int>((1 << n), -1));
      for (int i = 0; i < n; ++i) {
        if (i == start) {
          d[i][(1 << i)] = INF;
        } else {
          d[i][(1 << i)] = 0;
        }
      }
      for (int mask = (1 << start); mask < (1 << n); ++mask) {
        if (((mask >> start) & 1) == 0) {
          continue;
        }
        for (int end = 0; end < n; ++end) {
          if (start == end || ((mask >> end) & 1) != 0) {
            continue;
          }
          int maske = mask + (1 << end);
          for (int from = 0; from < n; ++from) {
            if (from != end && ((mask >> from) & 1) != 0) {
              d[end][maske] =
                  max(d[end][maske], min(d[from][mask], d1[from][end]));
            }
          }
          ans = max(ans, min(d[end][(1 << n) - 1], d2[end][start]));
        }
      }
    }
  } else {
    ans = d2[0][0];
  }
  cout << ans << '\n';
  return 0;
}
