mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N, D = map(int, input().split()) T = [0] * N K = [0] * N for i in range(N): t, k = map(int, input().split()) T[i] = t K[i] = k dp = [[0] * 2 for _ in range(N+1)] dp[0][1] = -(10**10) for i in range(N): dp[i+1][0] = max(dp[i][0] + T[i], dp[i][1] + T[i] - D) dp[i+1][1] = max(dp[i][1] + K[i], dp[i][0] + K[i] - D) print(max(dp[-1])) if __name__ == '__main__': main()