#include <bits/stdc++.h>
using namespace std;
int a[36][10005], a1[36][36], f[1 << 18][36];
int n, m, ans;
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]);
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) {
      int x1 = 0x3f3f3f3f;
      for (int k = 0; k < m; k++) x1 = min(x1, abs(a[i][k] - a[j][k]));
      a1[i][j] = a1[j][i] = x1;
    }
  for (int s = 0; s < n; s++) {
    memset(f, 0, sizeof(f));
    f[1 << s][s] = 0x3f3f3f3f;
    for (int i = 0; i < 1 << n; i++)
      for (int j = 0; j < n; j++)
        if (f[i][j])
          for (int k = 0; k < n; k++)
            if (!(i & 1 << k))
              f[i | 1 << k][k] = max(f[i | 1 << k][k], min(f[i][j], a1[j][k]));
    for (int i = 0; i < n; i++) {
      int x1 = f[(1 << n) - 1][i];
      for (int j = 0; j + 1 < m; j++) x1 = min(x1, abs(a[i][j] - a[s][j + 1]));
      ans = max(ans, x1);
    }
  }
  printf("%d\n", ans);
}
