local n = io.read("*n", "*l")
local titles = {}
local len = {}
for i = 1, n do
  local title, l = io.read():match("(%w+) (%d+)")
  len[i] = tonumber(l)
  titles[title] = i
end
local ret = 0
local p = titles[io.read()]
for i = p + 1, n do
  ret = ret + len[i]
end
print(ret)
