use strict; use warnings; my $n = <>; my @a = split ' ', <>; my $max = $n; for my $i (reverse @a){ if($i == $max){ $max--; } } print $max;