import Debug.Trace

main :: IO ()
main = do
  n <- readLn :: IO Int
  ns <- map read . words <$> getLine :: IO [Int]
  print $ solve n ns

solve :: Int -> [Int] -> Int
solve n ns = --trace (show ms) $
             go ms
  where
    ms = zipWith (/=) [1..] ns
    go [_] = 0
    go [b1, b2]
      | b1 && b2 = 0
      | otherwise = 1
    go (b1:b2:xs)
      | b1 && b2 = go xs
      | otherwise = 1 + go xs
