let () = Scanf.scanf "%d\n" @@ fun l ->
  let as_ = Array.init l @@ fun _ -> Scanf.scanf "%d\n" @@ fun a -> a in
  let dp1, dp2, dp3, dp4, dp5 =
    Array.fold_left (fun (dp1, dp2, dp3, dp4, dp5) a ->
      a + dp1,
      (if a < 2 then 2 - a else a mod 2) + min dp1 dp2,
      (if a < 1 then 1 else (a + 1) mod 2) + min dp1 (min dp2 dp3),
      (if a < 2 then 2 - a else a mod 2) + min dp1 (min dp2 (min dp3 dp4)),
      a + min dp1 (min dp2 (min dp3 (min dp4 dp5))))
    (0, 0, 0, 0, 0) as_ in
  Printf.printf "%d\n" @@ min dp1 (min dp2 (min dp3 (min dp4 dp5)))
