#二分ヒープ
class BinaryHeap
  def initialize(n, &b)
    @heap = Array.new(n)
    @size = 0
    #ex) |parent, child| parent <= child
    @b = b
  end
  def push(x)
    me = @size
    @size += 1
    while 0 < me do
      parent = (me - 1) >> 1
      break if @b.call(@heap[parent], x)
        @heap[me] = @heap[parent]
        me = parent
    end
    @heap[me] = x
  end
  def shift
    wk = @heap[0]
    me = 0
    @size -= 1
    x = @heap[@size]
    while me < @size do
      child = (me << 1) + 1
      break if child >= @size
      if (child + 1) < @size && @b.call(@heap[child + 1], @heap[child]) then
        child += 1
      end
      break if @b.call(x, @heap[child])
      @heap[me] = @heap[child]
      me = child
    end
    @heap[me] = x
    wk
  end
  def empty?
    @size == 0
  end
end

N, M = gets.chomp.split(" ").map(&:to_i)
W = []
N.times{
  W << gets.chomp.split(" ").map(&:to_i)
}

W.sort!{|a, b| a[0] <=> b[0]}
lst = BinaryHeap.new(N){|parent, child| parent >= child}

ans = 0
(1..M).each{|m|
  while (not W.empty?) && W.first[0] <= m do
    a, b = W.shift
    lst.push(b)
  end
  ans += lst.shift if not lst.empty?
}

puts ans
