import Data.List

solve :: Int -> [Int] -> Int
solve n	[] = n
solve n l
  | 0 /= f l = solve (n+1) (tail [if ll == (l!!0) then minimum l else if ll == minimum l then l!!0 else ll | ll <- l])
  | otherwise = solve n (tail l)
    where f l = (\(Just x) -> x) $ elemIndex (minimum l) l

main = do
 list <- fmap (map read . tail . words) getContents
 putStrLn $ unwords $ map show $ sort $	list
 print $ solve 0 list