let shuffle card_lst a = let rec shuffle' idx rest_lst head tail = match rest_lst with | [] -> head::tail | x::xs -> let head, tail = if idx = a then (x, tail) else (head, tail @ [x]) in shuffle' (idx + 1) xs head tail in shuffle' 0 card_lst (-1) [] let solve n a_lst = let card_lst = Array.init n (fun i -> i + 1) |> Array.to_list in let rec solve' rest_lst result = match rest_lst with | [] -> result | x::xs -> let result = shuffle result (x - 1) in solve' xs result in solve' a_lst card_lst |> List.hd let read_int_int () = read_line () |> Str.split (Str.regexp_string " ") |> List.map int_of_string |> fun lst -> (List.nth lst 0, List.nth lst 1) let () = let n, _ = read_int_int () and a_lst = read_line () |> Str.split (Str.regexp_string " ") |> List.map int_of_string in solve n a_lst |> string_of_int |> print_endline