import qualified Data.ByteString.Char8 as C
import Data.Vector.Unboxed

main = C.interact $ put . sol . get

get = unfoldr (C.readInt . C.dropWhile (<'0'))

put = C.pack . show

sol v = f 0 (v!0)
  where
  f c 0   = c
  f c 1   = c + if v!1==1 then 1 else 0
  f c i
    | v!i==i && v!(i-1)==i-1  = f (c+1) (i-2)
    | v!i==i                  = f (c+1) (i-1)
    | otherwise               = f c (i-1)