$n=<>; @r=(0,glob<>); $a=1; for$i(1..$n){ if($r[$i]==$n){ print $c+1; exit; } if($b<$r[$i]){ $b=$r[$i]; } if($i==$a){ $a=$b; $c+=1; } }