program ioi_to_oio
  implicit none
  integer :: n, a(500000), x(0:500000), dp(500000), i, j, k, d
  character(500000) :: s
  a = 0
  x = 0
  dp = 0
  read(*,*) n
  read(*,*) s
  do i = 1, n
    if (s(i:i).eq."1") then
      a(i) = 1
      x(i) = x(i-1)+1
    end if
  end do
  do i = 3, n
    dp(i) = dp(i-1)
    if (a(i).eq.0) cycle
    if (a(i-2)-a(i-1).eq.1) then
      do d = 0, 2
        if (x(i-2).le.d) exit
        j = i-2-(x(i-2)-d)
        k = 0
        if (j.ge.1) k = dp(j)
        dp(i) = max(dp(i),x(i-2)-d+k)
      end do
    end if
    if (i-x(i)-1.ge.1.and.a(i-x(i)-1).eq.1) then
      j = i-2-x(i)
      k = 0
      if (j.ge.1) k = dp(j)
      dp(i) = max(dp(i),x(i)+k)
    end if
  end do
  write(*,'(i0)') dp(n)
  stop
end program ioi_to_oio