import Control.Monad
import Data.List
main = do
  n <- readLn
  [s, t] <- transpose . map words <$> replicateM n getLine
  x <- getLine
  let idx = head [i | (a, i) <- zip s [0..], a == x]
  print . sum . drop (idx + 1) $ map read t