
import Foundation

func readInt() -> Int {
    return Int(readLine()!)!
}

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readIntPair() -> (a: Int, b: Int) {
    let x = readInts()
    return (a: x[0], b: x[1])
}

func readStrings() -> [String] {
    return Array(readLine()!.split(separator: " ").map { String($0) })
}


struct Music {
    var title: String
    var time: Int
}

var list: [Music] = []
let n = readInt()
for _ in 0..<n {
    let tokens = readStrings()
    list.append(Music(title: tokens[0], time: Int(tokens[1])!))
}
let s = readLine()!

var sleeping: Bool = false
var spend: Int = 0
for m in list {
    if sleeping {
        spend += m.time
    } else {
        if s == m.title {
            sleeping = true
        }
    }
}
print(spend)

