-- | Main entry point to the application.
module Main where
 
import Control.Applicative
import Control.Monad
import Data.List
import Data.Maybe

swap list a another
  | a == another = list
  | otherwise = list1 ++ [list !! another] ++ list2 ++ [list !! a] ++ list3 where
    list1 = take a list
    list2 = drop (succ a) $ take another list
    list3 = drop (succ another) list

moveminforward [] = []
moveminforward [a] = [a]
moveminforward list = swap list 0 $ fromJust $ elemIndex (minimum list) list

iter :: [Int] -> [Int] -> Int -> ([Int], Int)
iter [] sofar cnt = (sofar, cnt)
iter list@(x:xs) sofar cnt = iter (moveminforward xs) (x:sofar) (if xs /= (moveminforward xs) then succ cnt else cnt)

selsort ns = let (sortedlist, count) = iter (moveminforward ns) [] (if ns /= (moveminforward ns) then 1 else 0) in
    (reverse sortedlist, count)

-- | The main entry point.
main :: IO ()
main = do
    _ <- getLine
    ns <- concatMap (fmap (read :: String -> Int) . words) . lines <$> getContents
    -- let ns = [5,6,4,2,1,3]
    -- let ns = [5,2,4,6,1,3]
    -- let ns = [1,2,3,4,5]
    let (sortedlist, count) = selsort ns
    -- let (sortedlist, count) = selsort ns
    putStrLn $ unwords $ map show sortedlist
    print count