open Scanf
open Printf

type heap = Nil | Node of int * heap * heap

let rec merge a b =
  match a, b with
  | a, Nil -> a
  | Nil, b -> b
  | Node (av, al, ar), Node (bv, bl, br) ->
    if av > bv then
      Node (av, (merge ar b), al)
    else
      Node (bv, (merge br a), bl)

let is_empty = function
  | Nil -> true
  | _ -> false

let push a v = merge a (Node (v, Nil, Nil))
let peek = function
  | Nil -> invalid_arg "nil"
  | Node (v, _, _) -> v

let pop = function
  | Nil -> invalid_arg "nil"
  | Node (_, l, r) -> merge l r


let () =
  let n, m = scanf " %d %d" (fun a b -> a, b) in
  let ab = Array.init n (fun _ -> scanf " %d %d" (fun a b -> a, b)) in
  Array.sort compare ab;
  let k = ref 0 in
  let q = ref Nil in
  let ans = ref 0 in
  for i = m - 1 downto 0 do
    while !k < n && i + fst ab.(!k) <= m do
      q := push !q (snd ab.(!k));
      incr k
    done;
    if not (is_empty !q) then begin
      ans := !ans + peek !q;
      q := pop !q
    end;
  done;
  printf "%d\n" !ans