Scanf.scanf "%d %d" (fun x n ->
    let module S = Set.Make (struct type t = int let compare = compare end) in
    let p = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let set = Array.fold_left (fun set v -> S.add v set) S.empty p in
    let rec loop i =
        if not (S.mem (x - i) set) then x - i else
        if not (S.mem (x + i) set) then x + i else
            loop (i + 1)
    in
    loop 0 |> Printf.printf "%d\n"
)