let scan_int () = Scanf.scanf " %d" (fun x -> x)
let print_int n = Printf.printf "%d\n" n

module PriorityQueue :
  sig
    type 'a t
    type 'a heap
    type 'a pq
    exception Is_empty
    val init : ('a -> 'a -> int) -> int -> 'a pq
    val size : 'a pq -> int
    val push : 'a pq -> 'a -> unit
    val top  : 'a pq -> 'a
    val pop  : 'a pq -> unit
    val empty: 'a pq -> bool
  end = 
  struct
    type 'a t = Nil | Val of 'a
    type 'a heap = ('a t) array
    type 'a pq = {heap: 'a heap; compare: 'a -> 'a -> int; mutable size: int}
    exception Is_empty
    let swap a i j = let tmp = a.(i) in begin a.(i) <- a.(j); a.(j) <- tmp end
    let init comp max_size = {heap = Array.make (max_size+1) Nil; compare = comp; size = 0}
    let size pq = pq.size
    let t_compare pq i j =
      match pq.heap.(i), pq.heap.(j) with
        Nil, Nil -> 0 | Nil, _ -> -1 | _, Nil -> 1 | Val(a), Val(b) -> pq.compare a b 
    let push pq a =
      let _ = pq.size <- (pq.size + 1) in
      let _ = pq.heap.(pq.size) <- Val(a) in
      let rec upheap h i =
        if i > 1 && t_compare pq i (i/2) > 0 then
          let _ = swap h (i/2) i in upheap h (i/2) in
      upheap pq.heap pq.size
    let top pq =
      match pq.heap.(1) with Nil -> raise Is_empty | Val(a) -> a
    let pop pq =
      if pq.size = 0 then raise Is_empty
      else
        let _ = pq.heap.(1) <- Nil in
        let _ = swap pq.heap 1 pq.size in
        let _ = pq.size <- pq.size - 1 in
        let rec downheap h i = 
          let l = 2*i and r = 2*i+1 in
          let j = if l <= pq.size && t_compare pq l i > 0 then l else i in
          let j = if r <= pq.size && t_compare pq r j > 0 then r else j in
          if j <> i then let _ = swap h i j in downheap h j in
      downheap pq.heap 1
    let empty pq = pq.size = 0
  end

let () =
  let n = scan_int() and m = scan_int() in
  let arr = Array.make n (0, 0) in
  let rec read_loop i =
    if i < n then
      let a = scan_int() and b = scan_int() in 
      let _ = arr.(i) <- (a, b) in read_loop (i+1) in
  let _ = read_loop 0 in
  let f (la, lb) (ra, rb) = if la <> lb then la - lb else ra - rb in
  let _ = Array.fast_sort f arr in
  let pq = PriorityQueue.init compare n in
  let rec calc day index ret =
    if day > m then ret
    else 
      if index < n then
        let a, b = arr.(index) in
        if a = day then
          let _ = PriorityQueue.push pq b in calc day (index+1) ret
        else
          if not (PriorityQueue.empty pq) then
            let ret = ret + (PriorityQueue.top pq) in
            let _ = PriorityQueue.pop pq in calc (day+1) index ret
          else calc (day+1) index ret
      else
        if not (PriorityQueue.empty pq) then
          let ret = ret + (PriorityQueue.top pq) in
          let _ = PriorityQueue.pop pq in calc (day+1) index ret
        else calc (day+1) index ret in
  print_int (calc 1 0 0)