let minNumOfOps = List.foldBack (fun x t -> if x = t then t - 1 else t) let () = let n = stdin.ReadLine() |> int let xs = stdin.ReadLine().Split(' ') |> Array.map int |> List.ofArray in minNumOfOps xs n |> printfn "%d"