INF = 10 ** 18 n, d = map(int, input().split()) dp = [[0] * (n + 1) for _ in range(2)] dp[0][0] = 0 dp[1][0] = -INF for i in range(n): t, k = map(int, input().split()) dp[0][i + 1] = max(dp[0][i] + t, dp[1][i] + t - d) dp[1][i + 1] = max(dp[0][i] + k - d, dp[1][i] + k) print(max(dp[0][n], dp[1][n]))