N, D = map(int, input().split()) T, K = [0]*N, [0]*N for i in range(N): T[i], K[i] = map(int, input().split()) dp = [[0]*2 for _ in range(N)] dp[0][0] = T[0] dp[0][1] = K[0]-D for i in range(1,N): dp[i][0] = max(dp[i-1][0]+T[i],dp[i-1][1]-D+T[i]) dp[i][1] = max(dp[i-1][0]-D+K[i],dp[i-1][1]+K[i]) print(max(dp[-1]))