#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n;
int a[100010];

int main(){
	cin.tie(0);
  ios::sync_with_stdio(false);

    while(true) {
	cin >> n;
	if(n==0) break;
	for (int i = 1; i <= n; i++) cin >> a[i];
	a[0] = a[n+1] = 4;

	int res = 0;
	n += 2;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= 3; j++) {
			int color = j;
			int sum = 0, cnt = 1;
			int l = i - 1, r = i + 1;
			while (true) {
				while (a[l] == color) l--, cnt++;
				while (a[r] == color) r++, cnt++;
				if (cnt < 4) break;
				sum += cnt;
				cnt = 0;
				if (a[l] != a[r]) break;
				color = a[l];
			}
			res = max(res, sum);
		}
	}

	cout << n - res - 2 << endl;
    }

	return 0;
}

