from math import inf N,D=map(int,input().split()) X=[0]*(N+1) Y=[0]*(N+1) Y[0]=-inf for i in range(N): T,K=map(int,input().split()) X[i+1]=max(X[i],Y[i]-D)+T Y[i+1]=max(X[i]-D,Y[i])+K print(max(X[-1],Y[-1]))