L = gets.to_i
a = []
L.times do 
  a << gets.to_i
end

dp = Array.new(L+1){[10**16]*5}
dp[0][0] = 0
L.times do |i|
  dp[i+1][0] = dp[i][0] + a[i]
  dp[i+1][1] = [dp[i][1],dp[i][0]].min + (a[i] == 0 ? 2 : (a[i].even? ? 0 : 1))
  dp[i+1][2] = [dp[i][2],dp[i][1],dp[i][0]].min + (a[i].odd? ? 0 : 1)
  dp[i+1][3] = [dp[i][3],dp[i][2],dp[i][1]].min + (a[i] == 0 ? 2 : (a[i].even? ? 0 : 1))
  dp[i+1][4] = dp[i].min + a[i]
end
p dp[L].min
