// 2012/12/13 Tazoe

#include <iostream>
using namespace std;

int no(int C[10002], int i, int c)
{
	int p = i-1;
	int q = i+1;

	int nc = 1;

	while(C[p]==c){
		nc++;
		p--;
	}
	while(C[q]==c){
		nc++;
		q++;
	}

	if(nc<4)
		return 0;

	int sum = nc;

	while(C[p]!=0&&C[q]!=0&&C[p]==C[q]){
		c = C[p];
		nc = 0;

		while(C[p]==c){
			nc++;
			p--;
		}
		while(C[q]==c){
			nc++;
			q++;
		}

		if(nc<4)
			break;

		sum += nc;
	}

	return sum;
}

int main()
{
while(true){
	int N;
	cin >> N;

if(N==0)
break;

	int C[10002];
	C[0] = 0;
	for(int i=1; i<=N; i++){
		cin >> C[i];
	}
	C[N+1] = 0;

	int M = N;
	for(int i=1; i<=N; i++){
		for(int j=1; j<=3; j++){
			int n = no(C, i, j);

			if(N-n<M){
				M = N-n;
			}
		}
	}

	cout << M << '\n';
}

	return 0;
}