import           Control.Monad (replicateM)

main :: IO ()
main = do
  n <- readLn
  playlist <- replicateM n $ do
    [s, t] <- words <$> getLine
    pure (s, read t)
  x <- getLine
  print $ solve x playlist

solve :: String -> [(String, Int)] -> Int
solve x = sum . map snd . drop 1 . dropWhile (\(title, _) -> title /= x)
