#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>

using namespace std;

int minimum,N;

struct Info{
	Info(){
		color = succeed_num = 0;
		deleted = false;
	}
	int color,succeed_num;
	bool deleted;
};

int calc(Info* info,int left,int right){
	int sum = 0;

	while(left >= 0 && right <= N-1){
		if(info[left].color != info[right].color && info[left].succeed_num == 4){
			sum += 4;
			left--;
		}else if(info[left].color != info[right].color && info[right].succeed_num == 4){
			sum += 4;
			right++;
		}else if(info[left].color == info[right].color && info[left].succeed_num + info[right].succeed_num >= 4){
			sum += info[left].succeed_num + info[right].succeed_num;
			left--;
			right++;
		}else{
			break;
		}
	}

	return N - sum;
}

void func(){

	if(N == 1){
		printf("1\n");
		return;
	}

	Info info[N];

	int pre,count,tmp,index = 0;
	scanf("%d",&pre);

	count = 1;

	for(int loop = 1; loop < N; loop++){
		scanf("%d",&tmp);

		if(tmp == pre){
			count++;
			if(loop == N-1){
				info[index].color = pre;
				info[index].succeed_num = count;
				index++;
			}
		}else{
			info[index].color = pre;
			info[index].succeed_num = count;
			index++;
			count = 1;
			if(loop == N-1){
				info[index].color = tmp;
				info[index].succeed_num = 1;
				index++;
			}
		}
		pre = tmp;
	}

	minimum = N;

	for(int i = 0; i <= index-1; i++){
		if((i > 0 && info[i-1].succeed_num == 3) || (i <= index-2 && info[i+1].succeed_num == 3) || (i > 0 && i <= index-2 && info[i-1].color == info[i+1].color
		                                                          && info[i-1].succeed_num + info[i+1].succeed_num >= 3)){
			if(info[i].succeed_num == 1){
				if(info[i-1].color == info[i+1].color){
					Info new_info[index];
					for(int k = 0; k < index; k++)new_info[k] = info[k];
					new_info[i-1].succeed_num += 1;
					tmp = calc(new_info,i-1,i+1);
					minimum = min(minimum,tmp);
				}else{
					Info new_info[index];
					for(int k = 0; k < index; k++)new_info[k] = info[k];
					new_info[i].color = info[i-1].color;
					tmp = calc(new_info,i-1,i);
					minimum = min(minimum,tmp);
					for(int k = 0; k < index; k++)new_info[k] = info[k];
					new_info[i].color = info[i+1].color;
					tmp = calc(new_info,i,i+1);
					minimum = min(minimum,tmp);
				}
			}else{

				Info new_info[index];
				for(int k = 0; k < index; k++)new_info[k] = info[k];
				new_info[i].succeed_num -= 1;
				new_info[i-1].succeed_num += 1;
				tmp = calc(new_info,i-1,i);
				minimum = min(minimum,tmp);

				for(int k = 0; k < index; k++)new_info[k] = info[k];
				new_info[i].succeed_num -= 1;
				new_info[i+1].succeed_num += 1;
				tmp = calc(new_info,i,i+1);
				minimum = min(minimum,tmp);
			}
		}else if(i == 0 && info[i+1].succeed_num == 3){

			Info new_info[index];

			for(int k = 0; k < index; k++)new_info[k] = info[k];
			new_info[i].succeed_num -= 1;
			new_info[i+1].succeed_num += 1;
			tmp = calc(new_info,i,i+1);
			minimum = min(minimum,tmp);
		}else if(i == index-1 && info[i-1].succeed_num == 3){

			Info new_info[index];
			for(int k = 0; k < index; k++)new_info[k] = info[k];
			new_info[i].succeed_num -= 1;
			new_info[i-1].succeed_num += 1;
			tmp = calc(new_info,i-1,i);
			minimum = min(minimum,tmp);
		}
	}

	printf("%d\n",minimum);

}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 2856