using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
using System.IO;

namespace AOJ2
{
    class Program
    {

        private static StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
        static void Main()
        {
            while (true)
            {
                var n = int.Parse(sc.Scan());
                var minNum = n;
                if (n == 0) break;
                var data = new int[n];
                for (int i = 0; i < n; i++)
                {
                    data[i] = int.Parse(sc.Scan());
                }
                var flg = false;
                for (int i = 1; i < n; i++)
                {
                    if (i + 3 > n - 1)
                    {
                        i = n - 5;
                        flg = true;
                    }
                    if (data[i + 1] == data[i + 2] && data[i + 1] == data[i + 3])
                    {
                        var datac = (int[])data.Clone();
                        datac[i] = data[i + 1];
                        minNum = Check(minNum, datac);
                    }
                    else if (data[i] == data[i + 2] && data[i] == data[i + 3])
                    {
                        var datac = (int[])data.Clone();
                        datac[i + 1] = data[i];
                        minNum = Check(minNum, datac);
                        i += 1;
                    }
                    else if (data[i] == data[i + 1] && data[i] == data[i + 3])
                    {
                        var datac = (int[])data.Clone();
                        datac[i + 2] = data[i];
                        minNum = Check(minNum, datac);
                        i += 1;
                    }
                    else if (data[i] == data[i + 1] && data[i] == data[i + 2])
                    {
                        var datac = (int[])data.Clone();
                        datac[i + 3] = data[i];
                        minNum = Check(minNum, datac);
                        i += 2;
                    }
                    if (flg) break;

                }

                Console.WriteLine(minNum);

            }
        }

        private static int Check(int minNum, int[] data)
        {
            var ans = Solve(data.ToList());
            return minNum > ans ? ans : minNum;
        }
        private static int Solve(List<int> data)
        {
            var before = 0;
            var start = 0;
            var end = 0;
            for (int i = 0; i < data.Count; i++)
            {
                if (before == data[i])
                {
                    end = i;
                    if (i == data.Count - 1 && end - start + 1 > 3)
                    {
                        data.RemoveRange(start, end - start + 1);
                        return Solve(data);
                    }
                }
                else
                {
                    if (end - start + 1 > 3)
                    {
                        data.RemoveRange(start, end - start + 1);
                        return Solve(data);
                    }
                    else
                    {
                        before = data[i];
                        start = i;
                        end = i;
                    }
                }
            }
            return data.Count;
        }
    }

    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        private byte read()
        {
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    return 0;
                }
            }
            return buf[ptr++];
        }
        public char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
    }
}

Measured memory_bytes: 8540