#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 16;
const int inf = 1000000007;
int dp[(1 << MAX_N) + 5][MAX_N][MAX_N];
int a[MAX_N][10005];
int cost1[MAX_N][MAX_N], cost2[MAX_N][MAX_N];
int n, m;
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]);
    }
  }
  if (n == 1) {
    int res = inf;
    for (int j = 1; j < m; j++) {
      res = min(res, abs(a[0][j] - a[0][j - 1]));
    }
    cout << res;
    return 0;
  }
  for (int first = 0; first < n; first++) {
    for (int last = 0; last < n; last++) {
      if (first != last) {
        cost2[first][last] = inf;
        for (int j = 1; j < m; j++) {
          cost2[first][last] =
              min(cost2[first][last], abs(a[first][j] - a[last][j - 1]));
        }
      }
    }
  }
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      if (x != y) {
        cost1[x][y] = inf;
        for (int j = 0; j < m; j++) {
          cost1[x][y] = min(cost1[x][y], abs(a[x][j] - a[y][j]));
        }
      }
    }
  }
  for (int s = 0; s < n; s++) {
    for (int i = 0; i < n; i++) {
      for (int mask = 1; mask < (1 << n); mask++) {
        dp[mask][s][i] = -1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    dp[1 << i][i][i] = inf;
  }
  for (int s = 0; s < n; s++) {
    for (int mask = 1; mask < (1 << n); mask++) {
      for (int i = 0; i < n; i++) {
        if (dp[mask][s][i] != -1) {
          for (int j = 0; j < n; j++) {
            if (!(mask & (1 << j))) {
              dp[mask + (1 << j)][s][j] = max(dp[mask + (1 << j)][s][j],
                                              min(dp[mask][s][i], cost1[i][j]));
            }
          }
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j != i) {
        res = max(res, min(dp[(1 << n) - 1][i][j], cost2[i][j]));
      }
    }
  }
  cout << res;
  return 0;
}
