#include <bits/stdc++.h>
const int N = 17, M = 1e4 + 5;
const int INF = 1 << 30;
int n, m, a[N][M], f[1 << N][N], g[N][N], h[N][N];
void init() {
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j) {
      g[i][j] = INF, h[i][j] = INF;
      for (int k = 1; k <= m; ++k)
        g[i][j] = std::min(g[i][j], std::abs(a[i][k] - a[j][k]));
      for (int k = 2; k <= m; ++k)
        h[i][j] = std::min(h[i][j], std::abs(a[i][k - 1] - a[j][k]));
    }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    for (int j = 1; j <= m; ++j) scanf("%d", &a[i][j]);
  init();
  for (register int i = 0; i < n; ++i)
    for (register int j = 0; j <= n; ++j) {
    }
  int ans = 0;
  for (int k = 0; k < n; ++k) {
    memset(f, 0, sizeof(f));
    f[1 << k][k] = INF;
    for (int S = 0; S < (1 << n); ++S)
      for (int i = 0; i < n; ++i)
        if (S & (1 << i)) {
          for (int j = 0; j < n; ++j) {
            if (!(S & (1 << j)))
              f[S | (1 << j)][j] =
                  std::max(f[S | (1 << j)][j], std::min(f[S][i], g[i][j]));
          }
        }
    for (int i = 0; i < n; ++i) {
      ans = std::max(ans, std::min(f[(1 << n) - 1][i], h[k][i]));
    }
  }
  printf("%d\n", ans);
  return 0;
}
