io = STDIN
N,M=io.gets.split.map(&:to_i)
dates=(1..M).to_a
pays= N.times.map{io.gets.split.map(&:to_i)}.
sort{|a,b|(b[1]<=>a[1]).nonzero?||b[0]<=>a[0]}.map do |a,b|
  if ix=dates.bsearch_index{|d|d>=a}
    dates.delete_at(ix)
    b
  else
    0
  end
end
p pays.inject(:+)
