require 'pp'

L = readline.to_i
A = []
L.times do |i|
  A << readline.to_i
end


dp = Array.new(5) { Array.new(L+1, 0) }

# pp A,dp

L.times do |i|
  dp[0][i+1] = dp[0][i] + A[i]
  dp[1][i+1] = [dp[0][i],dp[1][i]].min + (A[i]==0?2:(A[i]%2))
  dp[2][i+1] = [dp[0][i],dp[1][i],dp[2][i]].min + ((A[i]+1)%2)
  dp[3][i+1] = [dp[0][i],dp[1][i],dp[2][i],dp[3][i]].min + (A[i]==0?2:(A[i]%2))
  dp[4][i+1] = [dp[0][i],dp[1][i],dp[2][i],dp[3][i],dp[4][i]].min + A[i]
end

puts [dp[0][L],dp[1][L],dp[2][L],dp[3][L],dp[4][L]].min

