n,d = map(int,input().split()) z = [list(map(int,input().split())) for i in range(n)] dp = [[-float("Inf"), -float("Inf")] for i in range(n+1)] # 東京, 京都 dp[0][0] = 0 for i,[t,k] in enumerate(z): #東京から dp[i+1][0] = max(dp[i+1][0], dp[i][0] + t) dp[i+1][1] = max(dp[i+1][1], dp[i][0] + k - d) #京都から dp[i+1][0] = max(dp[i+1][0], dp[i][1] + t -d) dp[i+1][1] = max(dp[i+1][1], dp[i][1] + k) print(max(dp[-1]))