from bisect import bisect_left,bisect_right from itertools import accumulate from sys import stdin def main(): 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_left(ND,d) r = bisect_right(ND,d+v) IMOS[l]+=1 IMOS[r]-=1 NS = [] L = list(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 if ok == 10**9+100: print(-1) else: print(ok) if __name__ == '__main__': main()