import Control.Applicative
import Data.Map (insert, (!), foldrWithKey, member)
import qualified Data.Map as M

add :: M.Map Int Int -> Int -> M.Map Int Int
add m x = if member (x - 1) m then insert x (m!(x - 1)) m else insert x x m

longest :: M.Map Int Int -> Int
longest m = 1 + (foldrWithKey f 0 m)
    where
        f x y = max (x - y)

main :: IO ()
main = do
    n <- readLn
    p <- mapM (\_->readLn) [1..n] :: IO [Int]
    putStrLn $ show $ (n - (longest $ foldl add M.empty p))
