=0;$n--) { if($nums[$n] == $tail) { $tail--; } } echo $tail; echo PHP_EOL;