N,D=map(int,input().split()) T=[] K=[] for i in range(N): t,k=map(int,input().split()) T.append(t) K.append(k) dp=[[0]*(N+1) for i in range(N+1)] dp[1][0]=T[0] dp[1][1]=K[0]-D for i in range(1,N): dp[i+1][0]=dp[i][0]+T[i] for j in range(N): if j<=i: if j%2: dp[i+1][j+1]=max(dp[i][j+1]+T[i],dp[i][j]+T[i]-D) else: dp[i+1][j+1]=max(dp[i][j+1]+K[i],dp[i][j]+K[i]-D) print(max(dp[N]))