fun main(args: Array<String>) {
    dwacon6thPrelimsA()
}

fun dwacon6thPrelimsA() {
    val n = readLine()!!.toInt()
    val stList = (1..n).map { readLine()!!.split(' ').let { Pair(it[0], it[1].toInt()) } }
    val x = readLine()!!

    val indexOfFirst = stList.indexOfFirst { it.first == x }

    val answer = stList.slice(indexOfFirst + 1..stList.lastIndex).map { it.second }.sum()

    println(answer)
}
