import Control.Monad (replicateM)
import Data.List (group)

main = do
    n <- readLn
    if n == 0 then return () else do
        seq <- replicateM n readLn
        print (solve n seq)
        main


solve :: Int -> [Int] -> Int
solve n seq = n - maxChainLength
    where
    seq' = map (\s -> (head s, length s)) $ group seq

    maxChainLength = maximum chainLengths

    chainLengths = chainLengths' [head seq'] (tail seq')
        where
        chainLengths' _ [] = []
        chainLengths' seq1@((t1,c1):_) seq2@((t2,c2):seq2')
            = l1 : l2 : chainLengths' ((t2,c2):seq1) seq2'
            where
            l1 = chainLength (change t2 seq1) seq2
            l2 = chainLength seq1 (change t1 seq2)

chainLength :: [(Int,Int)] -> [(Int,Int)] -> Int
chainLength seq1 seq2 = chainLength' seq1 seq2 0
    where
    chainLength' [] _ acc = acc
    chainLength' _ [] acc = acc
    chainLength' ((t1,c1):seq1) ((t2,c2):seq2) acc
        | t1 == t2 && c1 + c2 >= 4 = chainLength' seq1 seq2 (acc+c1+c2)
        | otherwise = acc

change :: Int -> [(Int,Int)] -> [(Int,Int)]
change _ [] = []
change t ((t1,1):[]) = [(t,1)]
change t ((t1,1):(t2,c2):seq)
    | t == t2 = (t,c2+1):seq
    | otherwise = (t,1):(t2,c2):seq
change t ((t1,c1):seq) = (t,1):(t1,c1-1):seq