import Control.Monad
readN :: String -> Int
readN s = read s

solve'' as b (Just x) = (b, x + 1) : as
solve'' as b Nothing = (b, 1) : as

solve' as b = solve'' as b (lookup (b - 1) as)

solve :: [Int] -> [(Int, Int)]
solve is = foldl solve' [] is

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