N,D = map(int,input().split()) dp = [0] * 2 dp[1] = -(1 << 60) for i in range(N): t,k = map(int,input().split()) new_dp = dp.copy() new_dp[0] = max(dp[0] + t, dp[1] + t - D) new_dp[1] = max(dp[1] + k, dp[0] + k - D) dp = new_dp print(max(dp))