let () = let m = Scanf.scanf "%d %d " (fun _ m -> m) in let rec read i acc = if i = m then acc else Scanf.scanf "%d " (fun i -> i) :: acc |> read (i + 1) in let rec doit x = function | [] -> x | a :: l -> doit (if x = 1 then a else if x > a then x else x - 1) l in read 0 [] |> doit 1 |> Printf.printf "%d\n"