{-# OPTIONS_GHC -O3 #-}
{-# LANGUAGE ViewPatterns, ScopedTypeVariables #-}

import qualified Data.ByteString as B (getLine)
import qualified Data.ByteString.Char8 as C (readInt, words)
import qualified Data.Maybe as M (fromJust)

readInt = fst . M.fromJust . C.readInt

run i (x:y:xs) ans | x == i || y == i + 1 = run (i + 1) (x:xs) (ans + 1)
                   | otherwise = run (i + 1) (y:xs) ans
run i [x] ans = ans

run2 i (x:y:xs) ans | x == i || y == i - 1 = run2 (i - 1) (x:xs) (ans + 1)
                    | otherwise = run2 (i - 1) (y:xs) ans
run2 i _ ans = ans

main = do
    (readInt -> n) <- B.getLine
    (map readInt . C.words -> xs) <- B.getLine
    putStrLn $ show $ min (run 1 xs 0) (run2 n (reverse xs) 0)
