{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad         (join)
import           Data.Bifunctor        (bimap)
import qualified Data.ByteString.Char8 as BC
import qualified Data.IntMap.Strict    as M
import           Data.List             (maximumBy, partition)
import           Data.Maybe            (fromJust)
import           Data.Ord              (comparing)

main :: IO ()
main = do
  n <- readLn
  vs <- getInts
  print $ solve n vs

solve :: Int -> [Int] -> Int
solve n vs
  | o1 /= e1 = n - v1 - w1
  | otherwise = min (n - v1 - w2) (n - v2 - w1)
    where
      ((o1, v1, v2), (e1, w1, w2)) = join bimap (findMaxAndSnd . count . fst . unzip) . partition (odd . snd) $ zip vs [1 .. n]

count :: [Int] -> M.IntMap Int
count xs = M.fromListWith (+) [(x, 1) | x <- xs]

findMaxAndSnd :: M.IntMap Int -> (Int, Int, Int)
findMaxAndSnd xs = (x1, v1, v2)
  where
    (x1, v1) = findMax xs
    v2 = findSnd xs x1

findMax :: M.IntMap Int -> (Int, Int)
findMax = maximumBy (comparing snd) . M.toAscList

findSnd :: M.IntMap Int -> Int -> Int
findSnd xs x
  | M.null ys = 0
  | otherwise = snd $ findMax ys
    where
      ys = M.delete x xs

readInts :: BC.ByteString -> [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words

getInts :: IO [Int]
getInts = readInts <$> BC.getLine
