#include <stdio.h>
#include <algorithm>

using namespace std;

int disp(int block[], int c, int n)
{
	int p, q;
	int i, j;
	
	for (i = 1; block[c + i] == block[c]; i++);
	for (j = 1; block[c - j] == block[c]; j++);
	
	if (i + j - 1 >= 4){
		p = c + i;
		q = c - j;
	}
	else {
		return (n);
	}
	
	while (block[p] != -1 && block[q] != -1){
		if (block[p] != block[q]){
			break;
		}
		for (i = 1; block[p + i] == block[p]; i++);
		for (j = 1; block[q - j] == block[q]; j++);
		
		if (i + j >= 4){
			p += i;
			q -= j;
		}
		else {
			break;
		}
	}
	
	int ret = 0;
	for (int i = p; block[i] != -1; i++){
		ret++;
	}
	for (int i = q; block[i] != -1; i--){
		ret++;
	}
	
	return (ret);
}

int main(void)
{
	int block[10002];
	int n;
	int ans;
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		block[0] = block[n + 1] = -1;
		for (int i = 1; i <= n; i++){
			scanf("%d", &block[i]);
			block[i]--;
		}
		
		ans = 10000;
		for (int i = 1; i <= n; i++){
			block[i] = (block[i] + 1) % 3;
			ans = min(disp(block, i, n), ans);
			block[i] = (block[i] + 1) % 3;
			ans = min(disp(block, i, n), ans);
			block[i] = (block[i] + 1) % 3;
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}