program speedrun
implicit none
integer N
character(100),allocatable,dimension(:)::s
integer,allocatable,dimension(:)::t
character(100)::x

integer::i
logical::sleep=.false.
integer::ans=0
read*,N
allocate(S(N),t(N))
do i=1,N
    read*,S(i),t(i)
end do
read*,x
do i=1,N
    if(sleep)ans=ans+t(i)
    if(S(i)==X)sleep=.true.
end do
print"(i0)",ans
end program speedrun