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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	while (cin >> N, N) {
		vector<int> x(N);
		for (int i = 0; i < N; i++) {
			cin >> x[i];
		}
		int res = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 1; j <= 3; j++) {
				int lb = i - 1, ub = i + 1, cnt = 1;
				while (0 <= lb && x[lb] == j) {
					cnt++;
					lb--;
				}
				while (ub < N && x[ub] == j) {
					cnt++;
					ub++;
				}
				if (cnt >= 4) {
					while (0 <= lb && ub < N && x[lb] == x[ub]) {
						int v = x[lb], add = 0;
						while (0 <= lb && x[lb] == v) {
							add++;
							lb--;
						}
						while (ub < N && x[ub] == v) {
							add++;
							ub++;
						}
						if (add <= 3) break;
						cnt += add;
					}
					res = max(res, cnt);
				}
			}
		}
		cout << N - res << endl;
	}
	return 0;
}

