class Heapq
  def initialize
    @heap = []
    @last = 0
  end

  def enqueue(v)
    @last += 1
    @heap[@last] = v
    i = @last
    while i > 1
      if v > @heap[i/2]
        @heap[i] = @heap[i/2]
        @heap[i/2] = v
        i /= 2
      else
        break
      end
    end
  end

  def dequeue
    return nil if empty?
    top = @heap[1]
    v = @heap[@last]
    @heap[@last] = nil
    @heap[1] = v
    @last -= 1
    i = 1
    while i < @last
      l = i*2
      r = i*2 + 1
      if @heap[l] && @heap[l] > v && (@heap[r].nil? || @heap[l] > @heap[r])
        @heap[i] = @heap[l]
        @heap[l] = v
        i = l
      elsif @heap[r] && @heap[r] > v
        @heap[i] = @heap[r]
        @heap[r] = v
        i = r
      else
        break
      end
    end
    top
  end

  def empty?
    @last.zero?
  end

  def length
    @last
  end
end

n, m = gets.split.map(&:to_i)
prices = Hash.new {|h,k| h[k] = []}
n.times do
  a, b = gets.split.map(&:to_i)
  prices[a] << b
end

ans = 0
queue = Heapq.new
(1..m).each do |day|
  prices[day].each do |v|
    queue.enqueue(v)
  end
  unless queue.empty?
    ans += queue.dequeue
  end
end

puts ans
