import sys input = sys.stdin.readline N,D=map(int,input().split()) DP=[0,-10**100] for i in range(N): NDP=[0,0] t,k=map(int,input().split()) NDP[0]=max(DP[0]+t,DP[1]+t-D) NDP[1]=max(DP[1]+k,DP[0]+k-D) DP=NDP print(max(DP))