line = readlines
len = line.length
i = 0

while i < len
    line[i] = line[i].chomp.split(' ')
    i += 1
end

N = line[0][0].to_i
X = line[N+1][0]

songs = []
for i in 1..N do
  songs.push(line[i][0])
end
x_id = songs.index(X) + 1

answer = 0
for i in (x_id+1)..N do
  answer += line[i][1].to_i
end

print answer