module Program open System let solve a = let len = a |> Array.length let dp = Array.zeroCreate (len + 1) Array.iter (fun x -> dp.[x] <- dp.[x-1] + 1) a let sortedNum = dp.[len] len - sortedNum let N = Console.ReadLine() |> ignore let a = Console.ReadLine().Split() |> Array.map int solve a |> Console.WriteLine