N, M = gets.split.map &:to_i
AB = $<.map{|s|
  s.split.map &:to_i
}
AB.sort_by!{|a, b|
  [-b, -a]
}

used = [false] * M
ans = 0
AB.each{|a, b|
  idx = (0..M-a).find{|i| !used[i] }
  next if !idx
  used[idx] = true
  ans += b
}
p ans