module Program open System let solve a = let len = a |> Array.length let a' = let comp = a |> Array.sort |> Array.indexed |> Array.map (fun (idx, x) -> (x, idx)) |> Map.ofArray a |> Array.map (fun x -> comp.[x] + 1) let dp = Array.zeroCreate (len + 1) a' |> Array.iter (fun a -> dp.[a] <- dp.[a-1] + 1) len - (dp |> Array.max) let N = Console.ReadLine() |> ignore let a = Console.ReadLine().Split() |> Array.map int solve a |> Console.WriteLine