$n = trim(fgets(STDIN)); $numstr = trim(fgets(STDIN)); $nums = explode(" ",$numstr); sort($nums); $act = 0; $tail = strlen($numstr); for($n--;$n > 0;$n--) { $pos = strpos($numstr, $nums[$n]); if($pos > $tail) { $n++; break; } $tail = $pos; } echo $n; echo PHP_EOL;