main = do
    n <- read <$> getLine
    let ans_ini = [[]]
    ans <- calc n ans_ini
    let ans_num = (length <$> ans) :: [Int]
    let k = (maximum ans_num) :: Int
    putStrLn $ show (n-k)

calc :: Int -> [[Int]] -> IO [[Int]]
calc 0 ac = return ac
calc n ac = do
    x <- read <$> getLine
    calc (n-1) (calc' x ac)

calc' :: Int -> [[Int]] -> [[Int]]
calc' a []       = []
calc' a [[]]     = [[a]]
calc' a (xs:xxs) =
    if (head xs == a-1)
        then (a:xs):xxs
        else xs:(calc' a xxs)