N, D = map(int, input().split()) T, K = map(int, input().split()) dp = np.zeros((N, 2), dtype=int) dp[0][0] = T dp[0][1] = K for i in range(1, N): T, K = map(int, input().split()) dp[i][0] = T + max(dp[i-1][0], dp[i-1][1] - D) dp[i][1] = K + max(dp[i-1][1], dp[i-1][0] - D) print(max(dp[N-1]))