#include <bits/stdc++.h>
using namespace std;
static inline void canhazfast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
  T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
  while (b) {
    T q = a / b;
    a %= b;
    swap(a, b);
    x0 -= q * x1;
    swap(x0, x1);
    y0 -= q * y1;
    swap(y0, y1);
  }
  x = x0;
  y = y0;
  return a;
}
int ctz(unsigned x) { return __builtin_ctz(x); }
int ctzll(unsigned long long x) { return __builtin_ctzll(x); }
int clz(unsigned x) { return __builtin_clz(x); }
int clzll(unsigned long long x) { return __builtin_clzll(x); }
int popcnt(unsigned x) { return __builtin_popcount(x); }
int popcntll(unsigned long long x) { return __builtin_popcountll(x); }
int bsr(unsigned x) { return 31 ^ clz(x); }
int bsrll(unsigned long long x) { return 63 ^ clzll(x); }
int a[16][10016];
int same[16][16];
int diff[16][16];
int dp[(1 << 16)][16][16];
template <typename T>
void umin(T &a, const T &b) {
  a = min(a, b);
}
template <typename T>
void umax(T &a, const T &b) {
  a = max(a, b);
}
int main() {
  canhazfast();
  int n, m, s, ans = 0;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) cin >> a[i][j];
  }
  if (n == 1) {
    ans = 1123456789;
    for (int j = 1; j < m; ++j) umin(ans, abs(a[0][j] - a[0][j - 1]));
    return cout << ans, 0;
  }
  s = 1 << n;
  for (int u = 0; u < n; ++u) {
    for (int v = 0; v < n; ++v) {
      if (u == v) continue;
      same[u][v] = 1123456789;
      diff[u][v] = 1123456789;
      for (int j = 0; j < m; ++j) {
        umin(same[u][v], abs(a[u][j] - a[v][j]));
        if (j) umin(diff[u][v], abs(a[u][j - 1] - a[v][j]));
      }
    }
  }
  for (int u = 0; u < n; ++u) {
    for (int v = 0; v < n; ++v) {
      if (u == v) continue;
      dp[(1 << u) | (1 << v)][u][v] = same[u][v];
    }
  }
  for (int msk = 0; msk < s; ++msk) {
    if (popcnt(msk) < 2) continue;
    for (int x = 0; x < n; ++x) {
      if (!(msk & (1 << x))) continue;
      for (int y = 0; y < n; ++y) {
        if (x == y || !(msk & (1 << y))) continue;
        for (int z = 0; z < n; ++z) {
          if (x == z || y == z || (msk & (1 << z))) continue;
          int tmp = min(dp[msk][x][y], same[y][z]);
          umax(dp[msk | (1 << z)][x][z], tmp);
        }
      }
    }
  }
  for (int u = 0; u < n; ++u) {
    for (int v = 0; v < n; ++v) {
      if (u == v) continue;
      int res = dp[s - 1][u][v];
      if (m > 1) umin(res, diff[v][u]);
      umax(ans, res);
    }
  }
  cout << ans;
  return 0;
}
