#require 'pp'

class Element
    attr_reader :data, :priority

    def initialize(data, priority)
        @data, @priority = data, priority
    end

    def <=>(other)
        @priority <=> other.priority
    end
end

class PriorityQueue
    def initialize
        @entries = []
    end

    def push(element)
        i = @entries.bsearch_index {|e| e.priority >= element.priority }
        if i
            @entries.insert(i, element)
        else
            @entries.push(element)
        end
    end

    def pop
        @entries.pop
    end

    def empty?
        @entries.empty?
    end
end

n, m = gets.chomp!.split(" ").map(&:to_i)
memo = {}
n.times do |i|
    a, b = gets.chomp!.split(" ").map(&:to_i)
    memo[a] ||= []
    memo[a] << Element.new(b, b)
end

pq = PriorityQueue.new

sum = 0
1.upto(m) do |i|
    if memo[i]
        memo[i].each do |e|
            pq.push(e)
        end
    end

    next if pq.empty?
    e = pq.pop
    sum += e.data
end

puts sum
