#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  long matrix[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> matrix[i][j];
    }
  }
  long threshold[n][n];
  long longthreshold[n][n];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i != j) {
        threshold[i][j] = INT_MAX;
        longthreshold[i][j] = INT_MAX;
      } else {
        threshold[i][j] = INT_MAX;
        longthreshold[i][j] = INT_MAX;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < m; ++k) {
        threshold[i][j] =
            min(threshold[i][j], abs(matrix[i][k] - matrix[j][k]));
        if (k > 0) {
          longthreshold[i][j] =
              min(longthreshold[i][j], abs(matrix[j][k] - matrix[i][k - 1]));
        }
      }
    }
  }
  long mincost[n][(long)pow(2, n)];
  long answer = -INT_MAX;
  for (int la = 0; la < n; ++la) {
    for (int i = 0; i < pow(2, n); ++i) {
      for (int j = 0; j < n; ++j) {
        mincost[j][i] = -INT_MAX;
      }
    }
    mincost[la][(1 << la)] = INT_MAX;
    for (int i = 0; i < pow(2, n); ++i) {
      for (int j = 0; j < n; ++j) {
        if ((i >> j) & 1) {
          for (int k = 0; k < n; ++k) {
            if (j != k && !((i >> k) & 1)) {
              mincost[k][(1 << k) | i] =
                  max(mincost[k][(1 << k) | i],
                      min(mincost[j][i], threshold[j][k]));
            }
          }
        }
      }
    }
    long full = pow(2, n) - 1;
    long minimum = -INT_MAX;
    for (int i = 0; i < n; ++i) {
      minimum = max(minimum, min(mincost[i][full], longthreshold[i][la]));
      if (minimum == 6) {
      }
    }
    answer = max(minimum, answer);
  }
  cout << answer << "\n";
}
