import Data.List

main = print . solve . drop 1 . map read . words =<< getContents

solve :: [Int] -> Int
solve (x:y:xs')
    | x == 1 = func y (x:xs') 2 1
    | otherwise = func x (y:xs') 2 0
    where
        func _ [] _ t = t
        func p (x:xs) i t
            | x /= i = func x xs (i+1) t
            | otherwise = func p xs (i+1) (t+1)
