let () =
  Scanf.scanf "%d" @@ fun l ->
  let a = Array.init (l+1) @@ fun i ->
    if i = 0 then 0
    else Scanf.scanf " %d" ((+) 0)
  in
  for i = 1 to l do a.(i) <- a.(i) + a.(i-1) done;
  let a x y = a.(y) - a.(x-1) in

  let dpl1, dpl2 = Array.make (l+1) 0, Array.make (l+1) 0 in
  let dpr1, dpr2 = Array.make (l+2) 0, Array.make (l+2) 0 in
  for i = 1 to l do
    dpl1.(i) <- min (a 1 i) @@
      dpl1.(i-1) + if a i i = 0 then 2 else a i i mod 2;
    dpl2.(i) <- min (a 1 (i-1)) (dpl2.(i-1) + (a i i + 1) mod 2);
  done;
  for i = l downto 1 do
    dpr1.(i) <- min (a i l) @@
      dpr1.(i+1) + if a i i = 0 then 2 else a i i mod 2;
    dpr2.(i) <- min (a (i+1) l) (dpr2.(i+1) + (a i i + 1) mod 2);
  done;

  Array.init (l+1) (fun i ->
    dpl1.(i) + dpr1.(i+1)
    |> min (dpl1.(i) + dpr2.(i+1))
    |> min (dpl2.(i) + dpr1.(i+1)))
  |> Array.fold_left min max_int
  |> Printf.printf "%d\n"