#include <bits/stdc++.h>
using std::min;
int n, m, a[17][10005], dis[20][20], dp[16][1 << 16][16], ans;
int c(int x, int y) {
  int t = 0x3f3f3f3f3f;
  for (int i = 1; i < m; i++) t = std::min(t, abs(a[x][i] - a[y][i + 1]));
  return t;
}
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]);
  memset(dis, 0x3f, sizeof(dis));
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      for (int k = 1; k <= m; k++)
        dis[i][j] = dis[j][i] = std::min(dis[i][j], abs(a[i][k] - a[j][k]));
  for (int i = 0; i < n; i++) dp[i][1 << i][i] = 0x3f3f3f3f3f;
  for (int i = 1; i < 1 << n; i++)
    for (int j = 0; j < n; j++)
      if (i & (1 << j)) {
        for (int k = 0; k < n; k++)
          if (i & (1 << k)) {
            for (int h = 0; h < n; h++)
              if ((i & (1 << h)) == 0) {
                dp[j][i | (1 << h)][h] = std::max(dp[j][i | (1 << h)][h],
                                                  min(dp[j][i][k], dis[k][h]));
              }
          }
      }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      ans = std::max(ans, min(dp[i][(1 << n) - 1][j], c(j, i)));
    }
  printf("%d\n", ans);
}
