import Control.Monad

main = do
  n <- readLn :: IO Int
  sts <- replicateM n ((\x -> (x !! 0, read (x !! 1))) . words <$> getLine) :: IO [(String, Int)]
  x <- getLine :: IO String
  putStrLn $ show $ sleep x sts

foldlState :: (a -> c -> b -> (a, c)) -> a -> c -> [b] -> a
foldlState f a s l = fst $ foldl (\(a,s) -> f a s) (a, s) l

sleep x sts = foldlState step 0 False sts
    where step a b (s, t) = (a + if b then t else 0, b || s == x)
