let N = stdin.ReadLine() |> int let A = stdin.ReadLine().Split(' ') |> Array.map int let mutable count = 0 for i in N-1 .. -1 .. 0 do if A.[i] = N then let mutable find = N - 1 let mutable tmpcount = 1 for j in i-1 .. -1 .. 0 do if A.[j] = find then find <- A.[j] - 1 tmpcount <- tmpcount + 1 if tmpcount > count then count <- tmpcount printfn "%d" <| N - count