{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
-- {-# LANGUAGE MultiWayIf        #-}
{-# LANGUAGE OverloadedStrings #-}
-- {-# LANGUAGE BangPatterns #-}
-- {-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Data.Char
import           Data.Function              (on)
import           Data.Int
import           Data.List (intercalate)
import           Data.Tuple
import           System.IO                  hiding (char8)
-- import           Data.Array
-- import           Data.Array.Unboxed
-- import           Data.Array.IArray
-- import           Data.Array.ST
-- import           Data.Array.MArray
-- import           Data.Array.Unsafe
import           Data.ByteString.Builder
import qualified Data.ByteString.Char8      as BS
import qualified Data.ByteString.Lazy.Char8 as BL
import           Data.Ix
import           Data.Maybe
import           Data.Monoid                hiding ((<>))
-- import           Data.Graph
-- import           Data.Vector.Unboxed ((//), (++), (!), (!?))
-- import qualified Data.Vector.Unboxed as U
-- import           Data.IntSet (IntSet)
-- import qualified Data.IntSet as S
-- import           Data.IntMap.Strict         (IntMap)
-- import qualified Data.IntMap.Strict         as M
import           Data.Sequence ((|>), (<|), (><),ViewR(..), ViewL(..), Seq)
import qualified Data.Sequence              as Seq
import           Data.Foldable (toList, minimumBy)
-- import           Debug.Trace

main = do
  n <- readInt1 <$> BS.getLine
  ns <- readIntN <$> BS.getLine
  putTuple . solve n $ Seq.fromList ns
  -- print $ solve n ms (M.fromAscList $ zip ms ns)

-- product of cyclic permutation
-- solve n ns m = n - (length . nub $ map f ns) where
-- solve n ns m = map f ns where
--   f x = g x (m M.! x) x
--   g x y z = if x == y then z else g x (m M.! y) (min z y)

putTuple :: (Seq Int, Int) -> IO ()
putTuple (a, b) = do
  putIntN $ toList a
  print b

solve :: Int -> Seq Int -> (Seq Int, Int)
solve n ns = selection ns 0 0 where
  selection :: Seq Int -> Int -> Int -> (Seq Int, Int)
  selection ns c k
    | k == n = (ns, c)
    | otherwise = swap ns c k $ minimumIndex ns k
  minimumIndex :: Seq Int -> Int -> Maybe (Int, Int, Int)
  minimumIndex ns k = if w > v then Just (w, v, i) else Nothing where
    w = Seq.index ns k
    (v, i) = minimumBy (compare `on` fst) $ Seq.zip (Seq.drop k ns) (Seq.fromList [k+0..n])
  swap ns c k Nothing = selection ns c (k+1)
  swap ns c k (Just (w, v, i)) = selection ns' (c+1) (k+1) where
    ns' = Seq.update i w $ Seq.update k v ns

--  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --  --

format :: Show a => Maybe a -> IO ()
format Nothing  = putStrLn "NO"
format (Just a) = putStrLn "YES" >> print a

-- [1,2,3] -> 1 2 3
putIntN :: [Int] -> IO ()
putIntN = putStrLn . intercalate [' '] . map show

readInt1 :: BS.ByteString -> Int
readInt1 = fst . fromJust . BS.readInt

readInt2 :: BS.ByteString -> (Int,Int)
readInt2 = toTuple . readIntN

readInt3 :: BS.ByteString -> (Int,Int,Int)
readInt3 = toTriple . readIntN

readIntN :: BS.ByteString -> [Int]
readIntN =  map readInt1 . BS.words

readInt641 :: BS.ByteString -> Int64
readInt641 = fromIntegral . fst . fromJust . BS.readInteger

readInt642 :: BS.ByteString -> (Int64,Int64)
readInt642 = toTuple . readInt64N

readInt643 :: BS.ByteString -> (Int64,Int64,Int64)
readInt643 = toTriple . readInt64N

readInt64N :: BS.ByteString -> [Int64]
readInt64N =  map readInt641 . BS.words

readInteger1 :: BS.ByteString -> Integer
readInteger1 = fst . fromJust . BS.readInteger

readInteger2 :: BS.ByteString -> (Integer,Integer)
readInteger2 = toTuple . readIntegerN

readInteger3 :: BS.ByteString -> (Integer,Integer,Integer)
readInteger3 = toTriple . readIntegerN

readIntegerN :: BS.ByteString -> [Integer]
readIntegerN =  map readInteger1 . BS.words

toTuple :: [a] -> (a, a)
toTuple [x, y] = (x, y)

toTriple :: [a] -> (a, a, a)
toTriple [x, y, z] =(x, y, z)

fromTuple :: (a, a) -> [a]
fromTuple (x, y) = [x, y]

fromTriple :: (a, a, a) -> [a]
fromTriple (x, y, z) = [x, y, z]

-- if not applying, use "const"

applyTuple :: (a -> a') -> (b -> b') -> (a, b) -> (a', b')
applyTuple f g (x, y) = (f x, g y)

applyTriple :: (a -> a') -> (b -> b') -> (c -> c') -> (a, b, c) -> (a', b', c')
applyTriple f g h (x, y, z) = (f x, g y, h z)

Measured memory_bytes: 4264