import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLn >>= main'
    where
        main' n = breads >>= print . solve n 

solve :: Int -> [Int] -> Int
solve n vs = check as bs
    where
        check [(vx, lx)] [(vy, ly)]
            | vx /= vy =  0
            | otherwise = min lx ly
        check ((vx, lx) : xs) ys@[(vy, ly)]
            | vx /= vy = n - lx - ly
            | otherwise = check xs ys
        check xs@[(vx, lx)] ((vy, ly) : ys)
            | vx /= vy = n - lx - ly
            | otherwise = check xs ys
        check (x@(vx, lx) : xs) (y@(vy, ly) : ys)
            | vx /= vy = n - lx - ly
            | lx > ly = check (x : xs) ys
            | otherwise = check xs $ y : ys

        (as, bs) = split vs

        split = edit . foldr ff (True, ([] ,[]))
            where
                ff x (b, (xs, ys))
                    | b = (not b, (x : xs, ys))
                    | otherwise = (not b, (xs, x : ys))

                edit (_, (xs, ys)) = (groupf xs, groupf ys)

                groupf = sortBy (flip cmpf) . map ((,) <$> head <*> length) . group . sort 
                    where
                        cmpf (lv, ll) (rv, rl) = compare ll rl `mappend` compare lv rv

        

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine