import Data.List

main :: IO()
main = getContents >>= putStr.unlines.(\xs-> [unwords.map show $sort xs, show $solve 0 xs]).map read.words.(!!1).lines

solve    :: Int -> [Int] -> Int
solve n xs | xs == sort xs = n
solve n xs = let s = minimum xs in solve (n+1) $delete s xs