let bits = 60

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let as_ =
    Array.to_list @@
    Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let ls = Array.init bits @@ fun i ->
    List.length @@ List.filter (fun a -> 0 < (a land (1 lsl i))) as_ in
  let rs = Array.init bits @@ fun i ->
    List.length @@ List.filter (fun a -> 0 = (a land (1 lsl i))) as_ in
  Printf.printf "%d\n" @@ 
  Array.fold_left max
    (Array.fold_left ( + ) 0 @@ Array.init bits @@ fun i ->
      ( * ) (1 lsl i) @@
      if k land (1 lsl i) = 0
      then ls.(i)
      else max ls.(i) rs.(i)) @@
    Array.init bits @@ fun i ->
      if k land (1 lsl i) = 0
      then 0
      else Array.fold_left ( + ) 0 @@ Array.init bits @@ fun j ->
        ( * ) (1 lsl j) @@
        if k land (1 lsl j) = 0 && i < j || i = j
        then ls.(j)
        else max ls.(j) rs.(j)

