fun main(args: Array<String>) {
    val N = readInt()
    val list = (0 until N).map { readPair(String::toString, String::toInt) }.toList()
    val X = readString()
    println(list.dropWhile { it.first != X }.drop(1).sumBy { it.second })
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <S, T> readPair(s: (String) -> S, t: (String) -> T) =
    readLine()!!.split(" ").let { Pair(s(it[0]), t(it[1])) }
