// Try AtCoder
// author: Leonardone @ NEETSDKASU

let gets() = stdin.ReadLine().Split(' ') |> Array.map int

[<EntryPoint>]
let main _ =
   let [|n; k|] = gets()
   seq { 1 .. n }
   |> Seq.fold (fun r _ ->
          let [|a; b|] = gets()
          Map.fold (fun m p v ->
               let np = p ||| a
               if np > k then m
               else
                 if match Map.tryFind np m with
                     | None -> true
                     | Some(e) -> (b+v)>e
                 then Map.add np (v+b) m
                 else m) r  r) (Map.ofList [(0,0)])
   |> Map.toSeq
   |> Seq.map snd
   |> Seq.max
   |> printfn "%d"
   0