import Control.Monad

main = do
  n <- readLn
  ls <- replicateM n $ do
    [song, ms] <- words <$> getLine
    return (song, read ms)
  s <- getLine
  let ls' = tail . dropWhile ((/=s).fst) $ ls
  print . sum . map snd $ ls'