#include <bits/stdc++.h>
using namespace std;
int n, m, a[17][10005], G[17][17], TH[17][17], k, p, dp[17][17][1 << 16], ans;
bool vis[17][17][1 << 16];
int dfs(int sta, int x, int sit) {
  if (sit == (1 << n) - 1) return TH[x][sta];
  if (vis[sta][x][sit]) return dp[sta][x][sit];
  vis[sta][x][sit] = true;
  for (int i = 1; i <= n; i++)
    if (!(sit >> i - 1 & 1))
      dp[sta][x][sit] =
          max(dp[sta][x][sit], min(G[x][i], dfs(sta, i, sit | 1 << i - 1)));
  return dp[sta][x][sit];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  if (n == 1) {
    k = 2E9;
    for (int i = 1; i < m; i++) k = min(k, abs(a[1][i] - a[1][i + 1]));
    printf("%d", k);
    return 0;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i != j) {
        G[i][j] = 2E9;
        for (int k = 1; k <= m; k++)
          G[i][j] = min(G[i][j], abs(a[i][k] - a[j][k]));
        TH[i][j] = 2E9;
        for (int k = 1; k < m; k++)
          TH[i][j] = min(TH[i][j], abs(a[i][k] - a[j][k + 1]));
      }
  for (int i = 1; i <= n; i++) ans = max(ans, dfs(i, i, 1 << i - 1));
  printf("%d", ans);
  return 0;
}
