import Control.Monad
import Data.List
import Data.Map

readN :: String -> Int
readN s = read s

solve'' hm b (Just x) = Data.Map.insert b (x + 1) hm
solve'' hm b Nothing = Data.Map.insert b 1 hm

solve' hm b = solve'' hm b (Data.Map.lookup (b - 1) hm)

solve :: [Int] -> Map Int Int
solve is = Data.List.foldl' solve' empty is

main = do
        n <- readN <$> getLine
        l <- Data.List.map read <$> replicateM n getLine
        putStrLn $ show $ n - (maximum $ elems (solve l))
