#include <bits/stdc++.h>
int main(void) {
  long max, doko, ue, sita;
  long uebak, sitabak, kazu;
  int kaeruiro, currentiro, retu[10000];
  long i, result;
  char kieta;
  while (1) {
    scanf("%d", &max);
    if (!max) break;
    for (i = 0; i < max; i++) {
      scanf("%d", &retu[i]);
    }
    result = max;
    for (doko = 0; doko < max; doko++) {
      for (kaeruiro = 1; kaeruiro < 4; kaeruiro++) {
        currentiro = kaeruiro;
        ue = doko - 1;
        sita = doko + 1;
        kazu = 1;
        kieta = 0;
        do {
          uebak = ue;
          sitabak = sita;
          for (ue = ue; ue >= 0; ue--) {
            if (retu[ue] != currentiro) break;
            kazu++;
          }
          for (sita = sita; sita < max; sita++) {
            if (retu[sita] != currentiro) break;
            kazu++;
          }
          if (kazu < 4) {
            ue = uebak;
            sita = sitabak;
            break;
          }
          kieta = 1;
          if (retu[ue] != retu[sita]) break;
          if (ue == -1 && sita == max) break;
          kazu = 0;
          currentiro = retu[ue];
        } while (1);
        if (kieta == 0) ue++;
        if (ue + 1 + max - sita < result) result = ue + 1 + max - sita;
      }
    }
    printf("%d\n", result);
  }
  return 0;
}
