import Control.Monad (replicateM)
import Data.Array
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInts :: IO [Integer]
readInts = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readStrings :: IO [BS.ByteString]
readStrings = BS.words <$> BS.getLine

main :: IO ()
main = do
  (n:_) <- readInts
  st <- map (change . words) <$> replicateM (fromInteger n) getLine
  x <- getLine
  print $ solve st x

change :: [String] -> (String, Integer)
change (s:t:_) = (s, read t)

solve :: [(String, Integer)] -> String -> Integer
solve ((s, _):st) x
  | s == x = sum $ map snd st
  | otherwise = solve st x