fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val songs = mutableListOf<Pair<String, Int>>()

    repeat(n) {
        val (s, t) = readLine()!!.split(" ")
        songs.add(Pair(s, t.toInt()))
    }

    val x = readLine()!!

    var sec = 0
    var shouldCount = false
    songs.forEach {
        if (shouldCount) sec += it.second
        if (it.first.equals(x)) shouldCount = true
    }

    println(sec)
}