# No.561 東京と京都 import sys input = sys.stdin.readline def main(): N, D = tuple(map(int, input().rstrip().split())) A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(N)) dp = [[0] * N for _ in range(2)] dp[0][0], dp[1][0] = A[0][0], A[0][1] - D for i in range(1, N): t, k = A[i] dp[0][i] = max(dp[0][i - 1] + t, dp[1][i - 1] + t - D) dp[1][i] = max(dp[0][i - 1] + k - D, dp[1][i - 1] + k) print(max(dp[0][-1], dp[1][-1])) if __name__ == "__main__": main()