#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<list>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 10000;

/*
  pos ã¯4åé£ç¶ã«ãªã£ãä½ç½®
 */
int solve(int n,int pos,vector<pair<int,int> > in){
  int l = pos,r = pos;
  int tmp = -in[pos].second;//ï¼åãããã
  while(0 <= l && (in[l].second == 0 || in[l].first == in[pos].first))tmp += in[l].second,l--;
  while(r < (int)in.size() && (in[r].second == 0 || in[r].first == in[pos].first) )tmp += in[r].second,r++;
  if (tmp < 4)return n;
  n -= tmp;

  while(true){
    if (l < 0 || r == in.size())break;
    if (in[l].first != in[r].first)break;
    if (in[l].second + in[r].second < 4)break;
    n = n -(in[l].second+in[r].second);
    l--;r++;
  }
  return n;
}

int main(){
  int n;
  while(cin>>n &&n){
    int prev = -1,cnt=0;
    vector<pair<int,int> > a;
    rep(i,n){
      int tmp;
      cin>>tmp;
      if (tmp != prev){
	if (prev != -1){
	  a.push_back(make_pair(prev,cnt));
	}
	prev = tmp;
	cnt = 1;
      }else cnt++;
    }
    a.push_back(make_pair(prev,cnt));
    //rep(i,a.size())cout <<"(" << a[i].first <<"," << a[i].second <<") ";cout << endl;
    int mini = n;
    rep(i,(int)a.size()){
      if (i-1 >= 0){
	a[i].second--;a[i-1].second++;
	mini=min(mini,solve(n,i-1,a));
	a[i].second++;a[i-1].second--;
      }
      if (i+1 < a.size()){
	a[i].second--;a[i+1].second++;
	mini=min(mini,solve(n,i+1,a));
	a[i].second++;a[i+1].second--;
      }
    }
    cout << mini << endl;
  }
}