let rec enum_downto_fold a b v f =
  if a < b then v else enum_downto_fold (a-1) b (f v a) f

let () =
  Scanf.scanf "%d %d" @@ fun n k ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  enum_downto_fold 40 0 (0, min_int) (fun (sa, sb) i ->
    let b = 1 lsl i in
    let v0, v1 = Array.fold_left (fun (v0,v1) ai ->
      v0 + (ai land b), v1 + (ai lxor b) land b) (0, 0) a
    in
    if k land (1 lsl i) = 0 then
      sa + v0, sb + max v0 v1
    else begin
      sa + v1, max (sa + v0) (sb + max v0 v1)
    end)
  |> fun (sa,sb) -> Printf.printf "%d\n" (max sa sb)