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

h = Hash.new

n.times do 
    a, b = gets.split.map(&:to_i)
    
    unless h[a]
        h[a] = Array.new
    end

    h[a].push(b)
end

ans = 0
jobs = Array.new(0)
for day in 1..m
    if h[day] 
        h[day].each do |b|
            idx = jobs.bsearch_index { |x| x >= b }
            if jobs.size > 0 && idx
                p idx
                jobs.insert(idx, b)
            else
                jobs.push(b)
            end
        end
    end

    val = jobs.pop
    ans += val if val
end

puts ans
