fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val s = mutableListOf<String>()
    val t = mutableListOf<Int>()

    for (i in 0 until N) {
        val (S, T) = readLine()!!.split(" ")
        s.add(S)
        t.add(T.toInt())
    }

    val X = readLine()!!

    var started = false
    var time = 0
    for (j in 0 until N) {
        if (started) {
            time += t[j]
        } else {
            if (s[j] == X) started = true
        }
    }
    println(time)
}