program main

  implicit none
  
  integer :: i, n, tsum
  integer, allocatable :: t(:) 
  character(100) :: x 
  character(100), allocatable :: s(:) 


  read(*,*) n
  allocate( t(n))
  allocate( s(n))
  
  do i = 1, n
    read(*,*) s(i), t(i)
  end do

  read(*,*) x
  
  tsum = 0 
  do i = n, 1, -1
    if( s(i) == x ) exit
    tsum = tsum + t(i)
  end do
  print*, tsum


end program main
