#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int N;
  while(cin >> N, N){
    vector<int> c(N+1); FOR(i,0,N) scanf("%d",&c[i]);
    c[N] = 10;
    // i??????????????´??????
    int ans = 1e9;
    FOR(i,0,N) {
      // 2?????????
      FOR(j,1,4) {
        vector<int> chain = c;
        if(chain[i] == j) continue;
        chain[i] = j;
        FOR(k,0,10000) {
          bool del = false;
          int cnt = 0;
          FOR(l,0,(int)chain.size()-1) {
            if(chain[l] == chain[l+1]) cnt++;
            else {
              if(cnt >= 3) {
                chain.erase(chain.begin() + l - cnt, chain.begin() + l + 1);
                del = true;
                break;
              }
              cnt = 0;
            }
          }
          if(!del) {
            ans = min(ans, (int)chain.size() - 1);
            break;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}