L = gets.to_i

list = L.times.collect{gets.to_i}

c0 = 0
c1 = 0
c2 = 0
c3 = 0
c4 = 0

list.each{|a|
#p [c0, c1, c2, c3, c4]
	new_c0 = c0 + a
	new_c1 = [c0, c1].min         + (a >= 2 ? 0 : 2) + (a % 2 == 0 ? 0 : 1)
	new_c2 = [c0, c1, c2].min     + (a % 2 == 0 ? 1 : 0)
	new_c3 = [c0, c1, c2, c3].min + (a >= 2 ? 0 : 2) + (a % 2 == 0 ? 0 : 1)
	new_c4 = [c1, c2, c3, c4].min + a
	
	c0 = new_c0
	c1 = new_c1
	c2 = new_c2
	c3 = new_c3
	c4 = new_c4
}

#p [c0, c1, c2, c3, c4]
puts [c0, c1, c2, c3, c4].min


