#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 16) + 5;
const int INF = 0x3f3f3f3f;
int dp[maxn][16][16];
int n, m;
int a[20][10005];
int pre[20][20];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  memset(pre, INF, sizeof pre);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      for (int k = 0; k < m; ++k) {
        pre[i][j] = min(pre[i][j], abs(a[i][k] - a[j][k]));
      }
    }
  }
  for (int i = 0; i < n; ++i) dp[1 << i][i][i] = INF;
  int need = (1 << n) - 1;
  for (int i = 1; i <= need; ++i) {
    for (int xx = 0; xx < n; ++xx) {
      for (int j = 0; j < n; ++j) {
        if ((i & (1 << j)) == 0) continue;
        int front = i ^ (1 << j);
        for (int k = 0; k < n; ++k) {
          if ((front & (1 << k)) == 0) continue;
          dp[i][j][xx] = max(dp[i][j][xx], min(dp[front][k][xx], pre[k][j]));
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      int tmp = dp[need][i][j];
      for (int k = 0; k < m - 1; ++k) {
        tmp = min(tmp, abs(a[i][k] - a[j][k + 1]));
      }
      res = max(res, tmp);
    }
  }
  printf("%d\n", res);
  return 0;
}
