import Control.Applicative
import Control.Monad
import qualified Data.Vector as V
import Data.Array.IO

main = do
  n <- readLn :: IO Int
  s <- V.fromList <$> getLine

  dp_1101 <- newArray (0, n) (-inf) :: IO (IOArray Int Int)
  dp_1011 <- newArray (0, n) (-inf) :: IO (IOArray Int Int)
  dp_wait <- newArray (0, n) (-inf) :: IO (IOArray Int Int)

  writeArray dp_wait 0 0

  forM_ [0..n-1] $ \i -> do
    when (i+3 <= n && (V.toList . V.slice i 3) s == "101") $ do
      readArray dp_wait i >>= to dp_1011 (i + 3) 1
      readArray dp_1101 i >>= to dp_wait (i + 3) 1
      readArray dp_wait i >>= to dp_wait (i + 3) 1
    when (s V.! i == '1') $ do
      readArray dp_1011 i >>= to dp_1011 (i + 1) 1
      readArray dp_1101 i >>= to dp_1101 (i + 1) 1
      readArray dp_wait i >>= to dp_1101 (i + 1) 1
      readArray dp_1011 i >>= to dp_wait (i + 1) 1
    readArray dp_wait i >>= to dp_wait (i + 1) 0

  readArray dp_wait n >>= print

to :: IOArray Int Int -> Int -> Int -> Int -> IO ()
to a i c v = readArray a i >>= writeArray a i . max (v + c)

inf :: Int
inf = 10^9