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

abs = []
n.times do
  e = gets.split.map(&:to_i)
  if i = abs.find_index{|ab| (e[0] < ab[0]) || (e[0] == ab[0] &&  e[1] >= ab[1]) }
    abs.insert(i, e)
  else
    abs << e
  end
end

score = 0

(1..m).each do |d|
  candidate = nil
  candidate_score = nil
  abs.each_with_index{|ab, idx|
    break if ab[0] > d
    if candidate.nil? || ab[1] > candidate_score
      candidate = idx
      candidate_score = abs[candidate][1]
    end
  }
  if candidate
    score += abs[candidate][1]
    abs.delete_at(candidate)
  end
end

p score