fun main(args: Array<String>) {
  val N = readInt()
  val ST = (1..N).map { readStrings() }.map { it[0] to it[1].toInt() }
  val V = readString()
  var f = false
  var sum = 0
  for (i in 0 until N) {
    val (S, T) = ST[i]
    if (S == V) {
      f = true
      continue
    }
    if (f) {
      sum += T
    }
  }
  println(sum)
}
 
fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }