import Control.Monad
import qualified Data.IntMap as M

main :: IO ()
main = do
  n <- readLn
  ps <- replicateM n readLn
  let tbl = M.fromList $ zip [1..] ps
  let tbl' = M.fromList $ zip ps [1..]
  print $ solve n tbl tbl'

solve :: Int -> M.IntMap Int -> M.IntMap Int -> Int
solve n tbl tbl' = let a = count 1
                       b = count' n
                    in n - 1 - (a `max` b)
  where
    count x | x >= n = 0
            | otherwise = let i = tbl' M.! x
                              j = tbl' M.! (x+1)
                          in if i < j then 1 + count (x+1) else 0
    count' x | x <= 1 = 0
             | otherwise = let i = tbl' M.! x
                               j = tbl' M.! (x-1)
                           in if i > j then 1 + count' (x-1) else 0

