      PROGRAM failingAsleep
      IMPLICIT NONE
      integer :: n
      integer :: t(50)
      character(100) :: s(50),x
      integer :: i
      logical :: flag = .false.
      integer(16) :: ans = 0
      
      read*,n
      do i = 1,n
        read*,s(i),t(i)
      end do
      read*,x
      
      
      do i = 1,n
        
        if( flag )then
          ans = ans + t(i)
        end if
        
        if(trim(s(i))==x)then
          flag = .true.
        end if
        
      end do
      
      print*,ans
      
      END PROGRAM