module Program open System let solve a = let len = a |> Array.length 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