n,m = gets.split(" ").map(&:to_i)
arr = n.times.map{gets.split.map(&:to_i)}
#a,b = arr.transpose

hash = {}
res = 0
arr.each do |i|
    hash[i[0]] = [[],0] if !hash.key?(i[0])
    hash[i[0]][0].push(i[1])
end
hash.each do |key,val|
    val[1] = val[0].sort!.last
end

(1..m).to_a.each do |i|
    max = [0, 0] #day, val
    (1..i).to_a.each do |j|
        max = [j,hash[j][1]] if hash.key?(j) && hash[j][1] > max[1]
    end
    res += hash[max[0]][0].pop if max[0] != 0
    hash[max[0]][1] = hash[max[0]][0].last.to_i
end

p res