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