open Scanf
open Printf
open Array

let max_i64,(++),i64 = Int64.(max_int,add,of_int)

let () = scanf " %d" @@ fun l ->
  let a = init l (fun _ -> scanf " %d" @@ fun v -> v) in
  let dp = make_matrix (l+1) 5 max_i64 in
  let f typ v = i64 @@
    match typ with
    | 0 | 4 -> (* zero *)
      v
    | 1 | 3 -> (* even >= 2 *)
      if v=0 then 2
      else if v mod 2 = 0 then 0 else 1
    | 2 | _ -> (* odd *)
      if v mod 2 = 1 then 0 else 1
  in
  let update i j v =
    dp.(i).(j) <- min dp.(i).(j) v
  in
  for k=0 to 4 do
    dp.(0).(k) <- 0L;
  done;
  for i=1 to l do
    for k=0 to 4 do
      for j=k to 4 do
        update i j @@ dp.(i-1).(k) ++ f j a.(i-1)
      done
    done
  done;
  (* iter (fun b ->
    iter (printf "%2Ld ") b;
    print_newline ()
  ) dp; *)
  printf "%Ld" @@ fold_left min max_i64 dp.(l)


