#include<iostream>
#include<algorithm>
using namespace std;
#define reps(i,b,n) for(int i = b ; i < n ; ++i )
#define rep(i,n) reps(i,0,n)
#define INF (1 << 30)
int n,table[10000];
int solve(int l){
  int r = l + 1 , cnt = n;
  while(true){
    int color = table[l] , dis = 0;
    while(table[l] == color && l >= 0 && ++dis) l--;
    while(table[r] == color && r < n && ++dis) r++;
    if(dis < 4) return cnt;
    else cnt -= dis;
  }
}
int main(){
  while(cin >> n , n){
    int ans = INF;
    rep(i,n) cin >> table[i];
    rep(i,n) reps(j,1,4) swap(j,table[i]) , ans = min(ans,solve(i)) , swap(j,table[i]);
    cout << ans << endl;
  }
}