import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val t = (1..n).map { Pair(sc.next(), sc.nextInt()) }
    val x = sc.next()

    val sumAll = t.map { it.second }.sum()
    var sum = 0
    for (i in 0 until n) {
        sum += t[i].second
        if (t[i].first == x) {
            break
        }
    }
    println(sumAll - sum)
}