#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;


int del(string s){
	bool hoge=true;
	string temp;
	while(hoge){
		hoge=false;
		int dt[s.size()];
		rep(i,s.size())dt[i]=0;
		rep(i,s.size()){
			if(i==0)dt[i]=1;
			else{
				if(s[i-1]==s[i])dt[i]=dt[i-1]+1;
				else dt[i]=1;
			}
		}
		temp="";
		for(int i=s.size()-1;i>=0;i--){
			if(dt[i]>3){
				hoge=true;
				i-=dt[i];
				i++;
			}else temp+=s[i];
		}
		s=temp;
	}
	return temp.size();
}

int func(string s){
	int mians=s.size();
	rep(p,s.size()){
		string alt=s;
		loop(c,1,4){
			alt[p]=(char)(c+'0');
			int left,right;left=right=p;
			while(alt[right]==alt[p])right++;
			while(alt[left]==alt[p])left--;
			if((right-1-left)<4)continue;
			mians=min(mians,del(alt));
		}
	}
	return mians;
}

int main(){
	int n;
	while(cin>>n,n){
		string s="";
		char ch;
		rep(i,n){cin>>ch;s+=ch;}
		cout<<func(s)<<endl;
	}
	return 0;
}