## subroutines

def erase(as, k)
  da = as[k]
  k0 = k - 1
  k1 = k + 1

  er = 0
  seq = 1

  loop do
    while as[k0] == da
      k0 -= 1
      seq += 1
    end
    while as[k1] == da
      k1 += 1
      seq += 1
    end

    return er if seq < 4

    er += seq
    seq = 0

    return er if as[k0] != as[k1] || k0 <= 0 || k1 > as.length

    da = as[k0]
  end
end

### main

loop do
  n = gets.strip.to_i
  break if n == 0

  as = n.times.map{gets.strip.to_i}
  nas = as.length
  as.unshift 0
  as.push 0
  #p as

  max_er = 0

  for k in (1..nas)
    ak = as[k]
    for i in (0..1)
      as[k] = (ak + i) % 3 + 1
      er = erase(as, k)
      max_er = er if max_er < er
    end

    as[k] = ak
  end

  puts (n - max_er)
end