# frozen_string_literal: true

n, m = gets.split.map(&:to_i)
ab = n.times.map { gets.split.map(&:to_i) }

hab = Hash.new { [] }

ab.each do |e|
  a = e[0]
  b = e[1]
  hab[b] += [a]
end

shab = hab.sort_by { |k, v| -k }

sum = 0
shab.each do |e|
  b = e[0]
  as = e[1].sort_by { |v| -v }
  as.each do |a|
    if a <= m
      sum += b
      m -= 1
    end
  end
end
puts sum
