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