let n, k = Scanf.scanf "%d %d" (fun n k -> n, k)
let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun i -> i))

let rec f d x =
  if d = -1 then x
  else
    let rec g i c =
      if i = n then c
      else g (i + 1) (c + (a.(i) lsr d) land 1) in
    let c = g 0 0 in
    f (d - 1) (x lor if c < n - c then 1 lsl d else 0)

let rec g d x =
  if d = -1 then x
  else
    let k = (k lsr d) land 1 in
    let b = (x lsr d) land 1 in
    if k = 1 && b = 0 then x
    else if k = 0 && b = 1 then g (d - 1) (x lxor (1 lsl d))
    else g (d - 1) x

let rec h i x s =
  if i = n then s
  else h (i + 1) x (s + a.(i) lxor x)

let () =
  let x = f 39 0 in
  let x = g 39 x in
  let a = h 0 x 0 in
  Printf.printf "%d\n" a
