open Scanf
open Printf
open Array

let bit k =
  let r = init 40 (fun i -> let p = 1 lsl i in k land p / p)
  in mapi (fun i _ -> r.(39-i)) r
let print_iarr a = iter (printf "%d ") a; print_newline ()

let () = scanf " %d %d" @@ fun n k ->
  let a = init n (fun _ -> scanf " %d" @@ fun v -> v) in
  let count = make_matrix 2 40 0 in
  iter (fun v ->
    let b = bit v in
    iteri (fun i w ->
      count.(w).(i) <- count.(w).(i) + 1
    ) b;
  ) a;
  (* print_iarr count.(0);
  print_iarr count.(1); *)
  let score i c = (1 lsl (39-i)) * c in
  let each =
    init 40 (fun i -> score i @@ max count.(0).(i) count.(1).(i))
  in
  (* print_iarr each; *)
  let cml = map (fun v -> v) each in
  for i=38 downto 0 do
    cml.(i) <- cml.(i) + cml.(i+1)
  done;
  (* print_iarr cml; *)
  let r = ref 0 in
  let sum = ref 0 in
  bit k |> iteri (fun i v ->
    if v=1 then (
      let c = !sum + score i count.(1).(i)
        + if i+1>=40 then 0 else cml.(i+1)
      in r := max !r c
    );
    sum := !sum + score i count.(1-v).(i);
  );
  print_int @@ max !r !sum


