class PriorityQueue
  attr_reader :size

  def initialize(order: :asc)
    @size = 0
    @nodes = []
  end

  def empty?
    @size.zero?
  end

  def push(node)
    index = size
    @size += 1

    while index > 0
      parent = (index - 1) / 2

      break if @nodes[parent].last <= node.last

      @nodes[index] = @nodes[parent]
      index = parent
    end

    @nodes[index] = node
  end

  alias_method :<<, :push

  def pop
    node = @nodes.first
    root = @nodes[size - 1]
    @size -= 1
    index = 0

    while index * 2 + 1 < @size
      left = 2 * index + 1
      right = left + 1

      if right < size && @nodes[right].last < @nodes[left].last
        left = right
      end

      break if @nodes[left].last >= root.last

      @nodes[index] = @nodes[left]
      index = left
    end

    @nodes[index] = root
    node.first
  end

  def top
    @nodes.first
  end
end

N, M = gets.split.map(&:to_i)

queries = N.times.map { gets.split.map(&:to_i) }

pque_day = PriorityQueue.new
pque_value = PriorityQueue.new

queries.each do |q|
  node = [q, q.first]
  pque_day.push(node)
end

ans = 0

1.upto(M) do |m|
  while !pque_day.empty? && pque_day.top.first.first <= m
    e = pque_day.pop
    pque_value.push([e, -e.last])
  end

  if !pque_value.empty?
    e = pque_value.pop
    ans += e.last
  end
end

puts ans
