
#include<stdio.h>
#include<algorithm>
using namespace std;
int n,cou,num,ans,str[2][10010];
int rest_count(int up,int down,int sum)
{
    if(up == 0 || down == cou)return sum;
    if(str[0][down + 1] == str[0][up - 1] && str[1][down + 1] + str[1][up - 1] >= 4)return rest_count(up - 1,down + 1,sum + str[1][down + 1] + str[1][up - 1]);
    return sum;
}
int main()
{
    while(scanf("%d",&n),n)
    {
        cou = -1;
        ans = n;
        for(int i = 0; i < n; i++)
        {
            scanf("%d",&num);
            if(i == 0 || num != str[0][cou])
            {
                cou++;
                str[0][cou] = num;
                str[1][cou] = 1;
            }
            else str[1][cou]++;
        }
        for(int i = 0; i < cou + 1; i++)
        {
            if(str[1][i] == 1)
            {
                if(str[0][i - 1] == str[0][i + 1] && str[1][i - 1] + str[1][i + 1] >= 3 && i != 0 && i != cou)ans = min(ans,n - rest_count(i - 1,i + 1,str[1][i - 1] + str[1][i + 1] + 1));
                if(str[1][i - 1] >= 3 && i != 0)ans = min(ans,n - rest_count(i - 1,i,1 + str[1][i - 1]));
                if(str[1][i + 1] >= 3 && i != cou)ans = min(ans,n - rest_count(i,i + 1,1 + str[1][i + 1]));
            }
            if(str[1][i - 1] >= 3 && i != 0)
            {
                str[1][i]--;
                ans = min(ans,n - rest_count(i - 1,i - 1,1 + str[1][i - 1]));
                str[1][i]++;
            }
            if(str[1][i + 1] >= 3 && i != cou)
            {
                str[1][i]--;
                ans = min(ans,n - rest_count(i + 1,i + 1,1 + str[1][i + 1]));
                str[1][i]++;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}