n,m = gets.chomp.split(" ").map(&:to_i)

job = []

for i in 1..n do
    job.push(gets.chomp.split(" ").map(&:to_i))
end
job.sort! {|a,b| (a[0] <=> b[0]).nonzero? || (b[0] <=> a[0])}

# p job

sum = 0
stack = []
for i in 1..m do
    if ! job.empty?
        while job[0][0] <= i
            tar = job.shift
            if stack.empty?
                stack.push(tar)
            else
                head = 0
                tail = stack.size-1
                mid = ((head+tail)/2.0).ceil
                while head <= tail
                    if tar[1] == stack[mid][1]
                        break
                    elsif tar[1] < stack[mid][1]
                        head = mid + 1
                    else
                        tail = mid - 1
                    end
                    mid = ((head+tail)/2.0).ceil
                end
                if mid > stack.size
                    stack.push(tar)
                else 
                    stack.insert(mid,tar)
                end
            end
            if job.empty?
                break
            end
        end
    end
    if ! stack.empty?
        tar = stack.shift
        sum += tar[1]
    end
    # print i," ", stack,"\n"
end

p sum