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

int n, m;
vector<int> a;

int up(int p) {
	while (p > 0 && a[p] == a[p - 1])
		p--;
	return p;
}

int dn(int q) {
	while (q < n - 1 && a[q] == a[q + 1])
		q++;
	return q;
}

void ct(int p, int q, int p1, int q1) {
	while (q - q1 + p1 - p > 1 && p >= 0 && q < n) {
		m = min(m, n - q + p - 1);

		p--;
		q++;
		p1 = p;
		q1 = q;
		if (p >= 0 && q < n && a[p] == a[q]) {
			p = up(p);
			q = dn(q);
		}
	}
}

int main()
{
	cin >> n;

	while (n > 0) {
		a.resize(n);
		m = n;

		for (int i = 0; i < n; i++)
			cin >> a[i];

		for (int i = 0; i < n; i++) {
			if (i > 0 && i < n - 1 && a[i - 1] != a[i] && a[i - 1] == a[i + 1])
				ct(up(i - 1), dn(i + 1), i, i + 1);
			else {
				if (i < n - 3 && a[i] != a[i + 1])
					ct(i, dn(i + 1), i, i + 1);
				if (i > 2 && a[i] != a[i - 1])
					ct(up(i - 1), i, i - 1, i);
			}
		}

		cout << m << endl;

		cin >> n;
	}

	return 0;
}
