object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val seq = Seq.fill(n, 2)(sc.next)
  val x = sc.next
  
  val index = seq.indexWhere(_(0) == x)
  
  println(seq.drop(index + 1).map(_(1).toInt).sum)
}
