local num, day = string.match(io.read(), "(%d+) (%d+)")
num, day = tonumber(num), tonumber(day)
local input = {}
for i = 1, num do
  local a, b = string.match(io.read(), "(%d+) (%d+)")
  table.insert(input, {
	day = tonumber(a),
    result = tonumber(b)
  })
end

table.sort(input, function (a, b)
    if a.result == b.result then
      return a.day >= b.day
    else
      return a.result >= b.result
    end
  end)

local count = 1
local sum = 0
while day > 0 and count <= #input do
  if day >= input[count].day then
    sum = sum + input[count].result
    day = day - 1
  end
  count = count + 1
end

print(sum)