#include <bits/stdc++.h>
using namespace std;
const int N = 17, M = 10010;
int n, m, start;
int arr[N][M], val[N][N], val2[N][N], dp[N][(1 << N)];
int solve(int pre, int mask) {
  if (mask == ((1 << n) - 1)) return val2[start][pre];
  if (dp[pre][mask] != -1) return dp[pre][mask];
  dp[pre][mask] = 0;
  for (int i = 0; i < n; i++) {
    if (((mask >> i) & 1) == 1) continue;
    dp[pre][mask] =
        max(dp[pre][mask], min(solve(i, (mask | (1 << i))), val[pre][i]));
  }
  return dp[pre][mask];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &arr[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      val[i][j] = val2[i][j] = 1000000010;
      for (int k = 0; k < m; k++) {
        val[i][j] = min(val[i][j], abs(arr[i][k] - arr[j][k]));
        if (k > 0) val2[i][j] = min(val2[i][j], abs(arr[i][k] - arr[j][k - 1]));
      }
    }
  }
  int ans = 0;
  for (start = 0; start < n; start++) {
    memset(dp, -1, sizeof(dp));
    ans = max(ans, solve(start, (1 << start)));
  }
  cout << ans << endl;
  return 0;
}
