N,D = map(int,input().split()) pq = [list(map(int,input().split()))for _ in range(N)] pq.sort(key=lambda x:(x[0],-x[1])) l = [0]+sorted(list(map(lambda x:x[1]-x[0],pq)),reverse=True) ans = 0 for i,x in enumerate(l[:-1]): ans = min(ans,x-pq[i][0]) print(ans)