n,m=map(int,input().split()) a=[] for i in range(n): a+=[list(map(int,input().split()))] a[-1].sort() from bisect import bisect_left,bisect_right X=10**9+1 ok=X ng=-1 while ok-ng>1: mid=(ok+ng)//2 q=[1]*(m+1) q[m]=0 for i in range(1,n): nq=[0]*(m+1) for j in range(m): if q[j]: l=bisect_left(a[i],a[i-1][j]) r=bisect_right(a[i],a[i-1][j]+mid) nq[l]+=1 nq[r]-=1 for j in range(m): nq[j+1]+=nq[j] nq[j]=int(nq[j]>0) q=nq if any(q): ok=mid else: ng=mid print(ok if ok