import java.lang.Math

val MOD: Int = 1000000000 + 7
val MODL: Long = MOD.toLong()

fun main(args: Array<String>)
{
    val n = read().toInt()
    val pl = mutableListOf<Pair<String, Int>>()
    for (i in 1..n) {
        val (s, t) = read().split(" ")
        pl.add(Pair<String, Int>(s, t.toInt()))
    }
    val x = read()

    var find = false
    var ans = 0
    for (i in 0 until n) {
       if (find) ans += pl[i].second
        if (pl[i].first == x) find = true
    }

    println(ans)
}

fun read(): String = readLine()!!
