import bisect import itertools def is_ok(v): S = list(range(len(D[0]))) for i in range(N-1): ND = D[i+1] IMOS = [0]*(len(ND)+1) for s in S: d = D[i][s] l = bisect.bisect_left(ND,d) r = bisect.bisect_right(ND,d+v) IMOS[l]+=1 IMOS[r]-=1 NS = [] L = list(itertools.accumulate(IMOS)) for j,l in enumerate(L): if l>0 and j 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok N,M = map(int, input().split()) L = [list(map(int, input().split())) for _ in range(N)] D = [] for l in L: D.append(sorted(list(set(l)))) ans = meguru_bisect(-1, 10**9+100) if ans == 10**9+100: print(-1) else: print(ans)