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