import Data.List

solve :: Int -> [Int] -> Int
solve n [] = n
solve n l
  | 0 /= getIndex l = solve (n+1) $ change l $ getIndex l
  | otherwise = solve n (tail l)
    where getIndex l = (\(Just x) -> x) $ elemIndex (minimum l) l
          change l i = tail $ (take i l) ++ [head l] ++ drop (i + 1) l
main = do
 list <- fmap (map read . tail . words) getContents
 putStrLn $ unwords $ map show $ sort $ list
 print $ solve 0 list