import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val title = mutableListOf<String>()
    val sec = IntArray(n)
    for (i in 0..n-1) {
        title.add(i, scanner.next())
        sec[i] = scanner.nextInt()
    }
    val startTitle = scanner.next()

    val sleepIndex = title.indexOf(startTitle) + 1

    var sum = 0
    for (i in sleepIndex..n-1) {
        sum += sec[i]
    }
    println(sum)
}