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