#
# Chain
#

while (n=gets.to_i)!=0

  queue=[]
  chain=[0]
  count=[0]

  n.times do
    char=gets.to_i
    if char==chain[-1]
      count[-1]+=1
    else
      chain<<char
      count<<1
    end
  end
  chain<<0
  count<<0

  # 色を変える候補
  2.upto(chain.size-2) do |i|
    if count[i]==1 && chain[i-1]==chain[i+1] && count[i-1]+count[i+1]>2
      queue<<[i, chain[i-1]]
    end
  end

  min=n
  while !queue.empty?
    _chain=chain.dup
    _count=count.dup
    idx, color=queue.shift
    _chain[idx]=color
    idx-=1
    while _chain[idx]==_chain[idx+1]
      _count[idx]+=_count[idx+1]
      _chain.delete_at(idx+1)
      _count.delete_at(idx+1)
      if _count[idx]>3
        _chain.delete_at(idx)
        _count.delete_at(idx)
      end
      if _chain[idx]==_chain[idx-1]
        idx-=1
      end
    end
    sum=0
    _count.each do |c|
      sum+=c
    end
    if sum<min
      min=sum
    end
  end

  puts min

end