n = gets.to_i
a = n.times.map{gets.to_i}
b = Array.new(5,10**15)
dp = Array.new(5).map{Array.new(n+1,0)}
dp[0] = [0,0,0,0,0]
for i in 0..n-1
    b[0] = dp[0][i]
    for j in 1..4
        b[j] = (b[j-1] < dp[j][i] ? b[j-1] : dp[j][i])
    end
    dp[0][i+1] = b[0]+a[i]
    dp[1][i+1] = b[1]+a[i]%2
    dp[1][i+1] += 2 if a[i] == 0
    dp[2][i+1] = b[2]+((a[i]%2)^1)
    dp[3][i+1] = b[3]+a[i]%2
    dp[3][i+1] += 2 if a[i] == 0
    dp[4][i+1] = b[4]+a[i]
end
ans = 10**18
for i in 0..4
    ans = dp[i][n] if ans > dp[i][n]
end
puts ans