#include <bits/stdc++.h>
using namespace std;
int N, M;
int inp[20][30005];
int dist[20][20];
int dist2[20][20];
int dp[1 << 16][16][16];
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++) {
    for (int j = 1; j <= M; j++) {
      scanf("%d", inp[i] + j);
    }
  }
  for (int i = 0; i < N; i++) {
    dp[1 << i][i][i] = 2e9 + 7;
    for (int j = i + 1; j < N; j++) {
      int diff = 2e9 + 7;
      for (int k = 1; k <= M; k++) {
        diff = min(diff, abs(inp[i][k] - inp[j][k]));
      }
      dist[i][j] = diff;
    }
  }
  int B = 1 << N;
  for (int b = 1; b < B; b++) {
    for (int s = 0; s < N; s++) {
      for (int e = 0; e < N; e++) {
        int bs = 1 << s, be = 1 << e;
        if ((b & (bs | be)) == (bs | be)) {
          for (int nxt = 0; nxt < N; nxt++)
            if ((~b) & (1 << nxt)) {
              dp[b | (1 << nxt)][s][nxt] =
                  max(dp[b | (1 << nxt)][s][nxt],
                      min(dp[b][s][e], dist[min(e, nxt)][max(e, nxt)]));
            }
        }
      }
    }
  }
  int ans = 0;
  for (int s = 0; s < N; s++) {
    for (int e = 0; e < N; e++) {
      int &ret = dp[B - 1][s][e];
      for (int k = 1; k < M; k++) {
        ret = min(ret, abs(inp[e][k] - inp[s][k + 1]));
      }
      ans = max(ans, ret);
    }
  }
  printf("%d", ans);
}
