read n
s=()
t=()
for i in `seq $n`
do
    read si ti
    s+=($si)
    t+=($ti)
done
read x
v=`echo ${s[@]} | tr ' ' '\n' | grep -n $x | tr -dc 0-9`
c=0
for i in `seq $v $((n-1))`
do
    c=$((c+t[i]))
done
echo $c
