#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 2000000000000000001 long long op(long long a,long long b){ return min(a,b); } long long e(){ return Inf64; } int main(){ int n,m; cin>>n>>m; vector a(n,vector (m)); rep(i,n){ rep(j,m)scanf("%lld",&a[i][j]); sort(a[i].begin(),a[i].end()); } long long ok = Inf32,ng = -1; while(ok-ng>1){ int mid = (ok+ng)/2; vector f(m,true); for(int i=1;i nf(m,false); int l = 0,r = 0,s = 0; rep(j,m){ while(r!=m && a[i-1][r]<=a[i][j]){ if(f[r])s++; r++; } while(l!=m && a[i-1][l]<=a[i][j] && a[i][j]-a[i-1][l]>mid){ if(f[l])s--; l++; } nf[j] = (s>0); } swap(f,nf); } bool F = false; rep(i,m){ if(f[i])F = true; } if(F)ok = mid; else ng = mid; } if(ok==Inf32)ok = -1; cout<