#include <cstdio>
#include <vector>
#include <cstddef>
#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int main()
{
	while (true)
	{
		int N, A; size_t MAX = 15000;

		vector<char> D;

		scanf("%d", &N);

		if (N == 0) { break; }

		for (int i = 0; i < N; i++)
		{
			scanf("%d", &A);

			D.push_back(A);
		}

		for (int i = 0; i < N; i++)
		{
			for (char j = 1; j <= 3; j++)
			{
				if (D[i] != j)
				{
					vector<char> E(D.begin(), D.end());

					E[i] = j;

					for (int k = 0; k < E.size() - 3; k++)
					{

					loop:;

						if (E.size() <= 3)
						{
							break;
						}

						if (E[k] == E[k + 1] && E[k + 1] == E[k + 2] && E[k + 2] == E[k + 3])
						{
							for (char l = 0; l < 3; l++)
							{
								E.erase(E.begin() + k);
							}

							while (k < E.size() - 1 && E[k] == E[k + 1])
							{
								E.erase(E.begin() + k);
							}

							if (k < E.size())
							{
								E.erase(E.begin() + k);
							}

							k = 0;

							goto loop;
						}
					}

					MAX = min(E.size(), MAX);
				}
			}
		}

		printf("%d\n", MAX);
	}

	return 0;
}

// Time : O( 3n ^ 3 )