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

int check(vector<int> character, int i, int color)
{
  if(character[i] == color) return character.size();

  character[i] = color;
  vector<int>::iterator it;
  while( 1 ){
    it = search_n(character.begin(), character.end(), 4, color);
    while(it!=character.end() && *it==color) it = character.erase(it);
    if(it==character.end())break;
    color = *it;
  }

  return character.size();
}

int main()
{
  int N, M;
  while(cin>>N, N){
    vector<int> character(N);
    for(int i=0; i<N; i++) cin>>character[i];

    M = 100000;
    for(int i=0; i<N; i++){
      for(int color=1; color<=3; color++){
        M = min(M, check(character, i, color));
      }
    }
    cout<<M<<endl;
  }
}