N, D = map(int, input().split()) TK = [list(map(int, input().split())) for i in range(N)] dp = [TK[0][0], TK[0][1]-D] for i in range(1, N): a = max(dp[0]+TK[i][0], dp[1]+TK[i][0] - D) b = max(dp[1]+TK[i][1], dp[0]+TK[i][1] - D) dp[0], dp[1] = a, b print(max(dp))