import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
-- import Data.Array
import Data.Array.Unboxed

main :: IO ()
main = do
  l <- readLn
  as <- replicateM l $ readLn :: IO [Int]
  print $ solve' as

solve' :: [Int] -> Int
solve' = minimum . foldl' f (replicate 5 0) 
  where
    f :: [Int] -> Int -> [Int]
    f as a = [
      (head as) + a,
      (minimum . take 2 $ as) + if a == 0 then 2 else if a `mod` 2 == 0 then 0 else 1,
      (minimum . take 3 $ as) + if a `mod` 2 == 0 then 1 else 0,
      (minimum . take 4 $ as) + if a == 0 then 2 else if a `mod` 2 == 0 then 0 else 1,
      (minimum as) + a]
