program ears
  implicit none
  integer(8), parameter :: infty = 100000000000000000_8
  integer :: l, i, j
  integer(8) :: a, dp(0:200000,5), x, y, c(5)
  a = 0
  dp = infty
  dp(0,1) = 0_8
  read(*,*) l
  do i = 1, l
    read(*,*) a
    x = 1_8-mod(a,2_8)
    y = mod(a,2_8)
    if (a.eq.0_8) then
      x = 1_8
      y = 2_8
    end if
    c = (/a,y,x,y,a/)
    do j = 1, 5
      dp(i,j) = min(dp(i,j),minval(dp(i-1,1:j))+c(j))
    end do
  end do
  write(*,'(i0)') minval(dp(l,1:5))
  stop
end program ears