#include <bits/stdc++.h>
using namespace std;
inline void proc_status() {
  ifstream t("/proc/self/status");
  cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
       << endl;
}
template <typename T>
inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
inline T read() {
  register T sum(0), fg(1);
  register char ch(getchar());
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fg = -1;
  for (; isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
  return sum * fg;
}
const int MAXN = 16, MAXM = (int)1e4;
int n, m;
int A[MAXN + 5][MAXM + 5];
inline void input() {
  n = read<int>(), m = read<int>();
  for (int i = 0; i < n; ++i)
    for (int j = 1; j <= m; ++j) A[i][j] = read<int>();
}
int w[MAXN + 5][MAXN + 5];
inline int DP(int st) {
  static int f[MAXN + 5][1 << MAXN];
  memset(f, 0, sizeof f);
  f[st][1 << st] = INT_MAX;
  for (int S = 1; S < 1 << n; ++S)
    for (int i = 0; i < n; ++i)
      if (f[i][S])
        for (int j = 0; j < n; ++j)
          if (!(S >> j & 1)) chkmax(f[j][S | 1 << j], min(f[i][S], w[i][j]));
  int ans = 0;
  for (int ed = 0; ed < n; ++ed)
    if (f[ed][(1 << n) - 1]) {
      int res = f[ed][(1 << n) - 1];
      for (int i = 1; i < m; ++i) chkmin(res, abs(A[ed][i] - A[st][i + 1]));
      chkmax(ans, res);
    }
  return ans;
}
inline void solve() {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (i != j) {
        int mn = INT_MAX;
        for (int k = 1; k <= m; ++k) chkmin(mn, abs(A[i][k] - A[j][k]));
        w[i][j] = mn;
      }
  int ans = 0;
  for (int i = 0; i < n; ++i) chkmax(ans, DP(i));
  printf("%d\n", ans);
}
int main() {
  input();
  solve();
  return 0;
}
