N, M = gets.split.map(&:to_i)
AB = []
N.times do
  line = gets.split.map(&:to_i)
  AB << line
end
AB.sort!
CD = []
ans = 0

(1..M).each do |n|
  while AB[0] && AB[0][0] == n
    a = AB[0][0]
    b = AB[0][1]
    if CD[0]
      ind = CD.bsearch_index{ |x| x > b } || CD.size
      CD.insert(ind, b)
    else
      CD.push(b)
    end
    AB.shift
  end
    
  if CD[0]
    ans += CD.pop
  end
end
  
print ans