#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int inf = 99999;

int check(vector<int> vec, int n)
{
	int c = 0, t = n;
	
	while(t-1 >= 0 && vec[t-1] == vec[t]){
		t--;
	}
	
	for(int i = 1; i <= 3 && t+i < vec.size(); i++){
		if(vec[t] != vec[t+i]){
			break;
		}
		c++;
	}
	if(c == 3){
		return t;
	}
	
	return -1;
}

int func(vector<int> vec, int n)
{
	vector<int> v = vec;
	int t = n;
	
	while(v.size()){
		t = check(v, t);
		if(t == -1){
			break;
		}
		
		while(t+1 < v.size() && v[t+1] == v[t]){
			v.erase(v.begin()+(t+1));
		}
		v.erase(v.begin()+t);
	}
	
	return v.size();
}

int main()
{
	int n, s, t;
	
	while(cin>>n && n){
		vector<int> vec;
		while(n--){
			cin >> t;
			vec.push_back(t);
		}
		s = inf;
		
		for(int i = 0; i < vec.size(); i++){
			for(int j = 1; j <= 3; j++){
				t = vec[i];
				vec[i] = j;
				s = min(s, func(vec, i));
				vec[i] = t;
			}
		}
		
		cout << s << endl;
	}
	
	return 0;
}