f=lambda:map(int,input().split()) N,D=f() T,K=0,-D for _ in '1'*N:t,k=f();T,K=max(T+t,K+t-D),max(T+k-D,K+k) print(max(T,K))