import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  solve <$> replicateM n f <*> getLine >>= print
  where
    f =(\[x, y] -> (x, read y)) <$> words <$> getLine

solve :: [(String, Int)] -> String -> Int
solve xs s = let Just t = lookup s $ snd db in t
  where
    db = foldr f (0, []) xs
    f (mn, i) (t, ls) = (t + i, (mn, t):ls)
