#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
int N;
int ans=1e9;
int color[10005];
int indexhash[10005];
struct balls
{
  int color,chain;
  balls(int color,int chain):
    color(color),chain(chain){};
};

void solve(vector<balls> data,int index)
{
  vector<balls> savedata=data;
  int rest=N;
  int l=-1;
  int r=-1;
  int now=indexhash[index];
  //cout << index << endl;
  if(index>1 && index<N)
    {
      l=indexhash[index-1];
      r=indexhash[index+1];
      if(l==r && now==l && now==r) return;
      if((now==l && now!=r && data[r].chain<3) ||
	 (now==r && now!=l && data[l].chain<3)) return;
      if(now==l && now!=r && data[r].chain==3)
	{
	  r++;
	  data[l].chain--;
	  rest-=4;
	  while(1)
	    {
	      if(r>=int(data.size()) || l<0) 
		{
		  ans=min(ans,rest);
		  return;
		}
	      if(data[l].color==data[r].color && 
		 data[l].chain+data[r].chain>=4)
		{
		  rest-=(data[l].chain+data[r].chain);
		}
	      else
		{
		  ans=min(ans,rest);
		  return;
		}
	      l--,r++;
	    }
	}
      if(now==r && now!=l && data[l].chain==3)
	{
	  l--;
	  data[r].chain--;
	  rest-=4;
	  while(1)
	    {
	      if(r>=int(data.size()) || l<0) 
		{
		  ans=min(ans,rest);
		  return;
		}
	      if(data[l].color==data[r].color && 
		 data[l].chain+data[r].chain>=4)
		{
		  rest-=(data[l].chain+data[r].chain);
		}
	      else
		{
		  ans=min(ans,rest);
		  return;
		}
	      l--,r++;
	    }
	}
      if(now!=l && now!=r && l!=r && data[l].color!=data[r].color)
	{
	  if(data[l].chain>=3)
	    {
	      l--;
	      rest-=4;
	      while(1)
		{
		  if(r>=int(data.size()) || l<0) 
		    {
		      ans=min(ans,rest);
		      break;
		    }
		  if(data[l].color==data[r].color && 
		     data[l].chain+data[r].chain>=4)
		    {
		      rest-=(data[l].chain+data[r].chain);
		    }
		  else
		    {
		      ans=min(ans,rest);
		      break;
		    }
		  l--,r++;
		}
	    }
	  data=savedata;
	  rest=N;
	  if(data[r].chain>=3)
	    {
	      r++;
	      rest-=4;
	      while(1)
		{
		  if(r>=int(data.size()) || l<0) 
		    {
		      ans=min(ans,rest);
		      return;
		    }
		  if(data[l].color==data[r].color && 
		     data[l].chain+data[r].chain>=4)
		    {
		      rest-=(data[l].chain+data[r].chain);
		    }
		  else
		    {
		      ans=min(ans,rest);
		      return;
		    }
		  l--,r++;
		}
	    }
	}
      if(now!=l && now!=r && l!=r && data[l].color==data[r].color)
	{
	  if(1+data[l].chain+data[r].chain>=4)
	    {
	      rest-=(1+data[l].chain+data[r].chain);
	      while(1)
		{
		  l--;
		  r++;
		  if(r>=int(data.size()) || l<0) 
		    {
		      ans=min(ans,rest);
		      return;
		    }
		  if(data[l].color==data[r].color && 
		     data[l].chain+data[r].chain>=4)
		    {
		      rest-=(data[l].chain+data[r].chain);
		    }
		  else
		    {
		      ans=min(ans,rest);
		      return;
		    }
		}
	    }
	}
    }
  else if(index==1)
    {
      if(indexhash[index]==indexhash[index+1]) return;
      else
	{
	  r=indexhash[index+1];
	  if(data[r].chain==3)
	    {
	      rest-=4;
	      ans=min(ans,rest);
	      return;
	    }
	}
    }
  else if(index==N)
    {
      if(indexhash[index]==indexhash[index-1]) return;
      else
	{
	  l=indexhash[index-1];
	  if(data[l].chain==3)
	    {
	      rest-=4;
	      ans=min(ans,rest);
	      return;
	    }
	}
    }
  
}

int main(void)
{
  while(cin >> N && N)
    {
      ans=1e9;
      vector<balls> firstballs;
      for(int i=1;i<=N;i++)
	{
	  cin >> color[i];
	}
      int nowcolor=color[1];
      int nowchain=1;
      indexhash[1]=0;
      for(int i=2;i<=N;i++)
	{
	  indexhash[i-1]=int(firstballs.size());
	  if(nowcolor==color[i]) nowchain++;
	  else
	    {
	      firstballs.push_back(balls(nowcolor,nowchain));
	      //indexhash[i-1]=int(firstballs.size()-1);
	      nowchain=1;
	      nowcolor=color[i];
	      if(i==N) 
		{
		  firstballs.push_back(balls(nowcolor,nowchain));
		  indexhash[i]=int(firstballs.size()-1);
		  break;
		}
	    }
	  if(i==N)
	    {
	      //indexhash[i-1]=int(firstballs.size()-1);
	      firstballs.push_back(balls(nowcolor,nowchain));
	      indexhash[i]=int(firstballs.size()-1);
	    }
	}
      /*
      for(int i=1;i<=N;i++)
	{
	  cout << indexhash[i] << ' ';
	}
      cout << endl;
      for(int i=0;i<int(firstballs.size());i++)
	{
	  cout << firstballs[i].color << ' ' << firstballs[i].chain << endl;
	  }*/
      for(int i=1;i<=N;i++) solve(firstballs,i);
      if(ans==1e9)
	{
	  cout << N << endl;
	}
      else
	{
	  cout << ans << endl;
	}
    }
  return 0;
}



Measured memory_bytes: 3276