
class P
  attr_accessor :color, :size
  def initialize(color=0, size=0)
    @color = color
    @size  = size
  end
end

# [Pair] -> [Pair]
def compless1(v)
  res = [v[0]]

  v[1..(-1)].each do |e|
    if e.color == res[-1].color
      res[-1].size += e.size
    else
      res << e
    end
  end

  res
end

# [Int] -> [Pair]
def compless2(v)
  res = []

  v.each{ |e| res << P.new(e, 1) }

  compless1(res)
end



# main
while (n = gets.chomp.to_i) != 0
  chain = []
  n.times { chain << gets.chomp.to_i }

  best = 0
  n.times do |i|
    1.upto(3) do |color|
      buf = chain.dup
      buf[i] = color
      v = compless2(buf)

      cnt = 0
      loop do
        v = compless1(v)

        nv = v.reject{ |e| e.size >= 4 }

        break if v == nv
        cnt += v.inject(0) { |acc, e| acc + (e.size >= 4 ? e.size : 0) }
        v = nv

        break if v == []
      end

      best = [best, cnt].max
    end
  end

  puts (n - best)
end