import Data.List (sortOn)

countMaxAscendings [_] _ maxC = maxC
countMaxAscendings (q0:q1:qs) c maxC
  | q0<q1 = countMaxAscendings (q1:qs) (c+1) $ max maxC (c+1)
  | otherwise = countMaxAscendings (q1:qs) 1 maxC

main :: IO ()
main = do
  n <- read <$> getLine :: IO Integer
  ps <- map read.lines <$> getContents :: IO [Integer]
  let qs = sortOn snd $ zip [1..] ps
  print $ n - countMaxAscendings (map fst qs) 1  1
