import Control.Monad

solve :: String -> [(String,Int)] -> Int
solve _ [] = 0
solve x ((s,t):xs) 
    | x == s = sum $ map snd xs
    | otherwise = solve x xs

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