-- extension section
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}
-- not supported extension
--{-# LANGUAGE Strict, StrictData #-}


module Main where

-- @@@@@@@@@@@@@@@@@--
-- import section   --
-- @@@@@@@@@@@@@@@@@--
--    import A.B.C( function name )  ...
-- or import A.B.C 

--
import Prelude hiding(
  getLine,
  getContents,
  lines,
  words
  )

-- standard library
import Control.Monad.ST


-- bytestring


-- containers


-- deepseq


-- regex-posix


-- text
import Data.Text.Lazy.IO as TIO
import Data.Text.Lazy as T
import Data.Text.Lazy.Read as TR

-- import Data.Text.IO as TIO
-- import Data.Text as T
-- import Data.Text.Read as TR



-- unordered-containers


-- vectors
import Data.Vector.Unboxed as UV
import Data.Vector.Unboxed.Mutable as MV


-- mtl


-- @@@@@@@@@@@@@@@@@--
-- main section     --
-- @@@@@@@@@@@@@@@@@--

main :: IO ()
main = do
  input <- getInput
  Prelude.putStr . show . getAnswer $ input 

-- main :: IO()
-- main = do
--   answer <- getInputandanser
--   putStr . show $ answer


-- @@@@@@@@@@@@@@@@@@@@@--
-- I/O DataType section --
-- @@@@@@@@@@@@@@@@@@@@@--
data Input = I (Int,[Int])
  deriving(Show)

type Answer = Int



-- @@@@@@@@@@@@@@@@@--
-- answerSection    --
-- @@@@@@@@@@@@@@@@@--
getInput :: IO Input
getInput = do
  Right (n, _) <- getLine >>= ( return . TR.decimal )
  numTexts <- getLine >>= ( return . (fmap textToInt) .words) 
  return (I (n, numTexts) )
  where 
    textToInt t = case TR.decimal t of
      Right (m , _) -> m


getAnswer :: Input -> Answer 
getAnswer ( I (_ , nums) ) = occur
  where go n ind (x:l@(x':l'@(x'':xs))) 
          | ind == x && (ind+1) == x' = go (n+1) (ind+2) l'
          | ind == x = go (n+1) (ind+1) l
          | (ind+1) == x' && (ind+2) == x''  = go (n + 1) (ind+3) xs
          | otherwise = go n (ind + 1) l
        go n ind (x:x':xs) | ind == x && (ind+1) == x' = go (n+1) (ind+2) xs
                           | ind == x = go (n+1) (ind+1) (x':xs)
                           | otherwise = go n (ind+1) (x':xs)
        go n ind (x:xs)  | ind == x = go (n+1) (ind+1) xs
                         | otherwise = go n (ind + 1) xs
        go n _ [] = n
        occur = go 0 1 nums 

getInputAndAnser :: IO Answer
getInputAndAnser = undefined


-- @@@@@@@@@@@@@@@@@@@@@@@@@@--
-- question unique section    --
-- @@@@@@@@@@@@@@@@@@@@@@@@@@--





-- @@@@@@@@@@@@@@@@@--
-- util section     --
-- @@@@@@@@@@@@@@@@@--

-- standard Input Function
gLine :: IO Text
gLine = getLine

gContents :: IO Text
gContents = getContents

