n,d = map(int,input().split()) t,k = map(int,input().split()) x,y = t, k-d for i in range(n-1): t,k = map(int,input().split()) x,y = max(x+t, y+t-d), max(x+k-d, y+k) print(max(x,y))