#require 'pp'
#require 'set'

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] << b
end

memo = memo.map {|k, v|
    [k, v.sort_by {|x| x }]
}.to_h

#pp memo

sum = 0
1.upto(m) do |i|
    next unless memo[i]
    x = memo[i].pop
    #pp x
    sum += x

    if memo[i].empty?
        memo.delete(i)
    elsif memo[i+1] == nil
        tmp = memo.delete(i)
        memo[i+1] = tmp
    else
        tmp = memo.delete(i)
        memo[i+1] = (memo[i+1] + tmp).sort_by{|x| x }
    end

    #pp memo
end

puts sum
