object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val playList = List.fill(sc.nextInt())(sc.next() -> sc.nextInt())
  val sleepySong = sc.next()
  val _ :: xs = playList.dropWhile(_._1 != sleepySong)
  println(xs.map(_._2).sum)
}
