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