n,d = map(int,input().split()) a,b = 0,-d for _ in range(n): t,k = map(int,input().split()) a,b = max(a,b-d)+t,max(a-d,b)+k print(max(a,b))