#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int check(const vector<int> &v, int cp){
	int lp = cp, rp = cp + 1;
	while(lp > 0){
		int c = v[lp];
		int tl, tr;
		for(tl = lp; v[tl] == c; --tl);
		for(tr = rp; v[tr] == c; ++tr);
		if((lp - tl) + (tr - rp) < 4){
			break;
		}
		lp = tl;
		rp = tr;
	}
	return lp + (v.size() - 1 - rp);
}

int main(){
	int n;
	while(scanf("%d", &n), n){
		vector<int> v(n + 2);
		for(int i = 1; i <= n; ++i){
			scanf("%d", &v[i]);
		}

		int ans = n;
		for(int i = 1; i <= n; ++i){
			int c = v[i];
			for(int j = 1; j <= 2; ++j){
				int t = (c + j) % 3;
				if(!t){ t = 3; }
				v[i] = t;
				ans = min(ans, check(v, i));
			}
			v[i] = c;
		}
		
		printf("%d\n", ans);
	}
}