module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () =
  let n, k = Scanf.scanf "%d %d\n" (fun n k -> n, k) in
  let abs = Array.init n (fun _ -> Scanf.scanf "%d %d\n" (fun a b -> a, b)) in
  Array.fold_left (fun m (a, b) ->
    IntMap.fold (fun a' b' m ->
      if (a lor a') <= k then IntMap.add (a lor a') (b + b') m else m) m m) (IntMap.singleton 0 0) abs
  |> (fun m -> IntMap.fold (fun _ -> max) m 0)
  |> Printf.printf "%d\n"