import java.util.*

fun main(args: Array<String>) {
    val argList = Scanner(System.`in`)

    val n = argList.nextLine().toInt()

    val music = mutableMapOf<String, Int>()
    val musicOrder = mutableListOf<String>()

    (1..n).forEach {
        val row = argList.nextLine().split(" ")
        music[row[0]] = row[1].toInt()
        musicOrder.add(row[0])
    }

    val x = argList.nextLine()

    val listenIndex = musicOrder.indexOf(x)
    val musicInSleeping = musicOrder.filterIndexed { index, s ->
        index > listenIndex
    }

    val seconds = musicInSleeping.mapNotNull {
        music[it]
    }

    println(seconds.sum())
}