-- heap
local Heap = {}
function Heap.new(upper_func)
    local self = setmetatable({}, {__index = Heap})
    self.a = {}
    self.upper_func = upper_func
    self.upper = function(k1, k2)
        assert(k1 < k2)
        if k1 == 0 then
            return false
        else
            return upper_func(self.a[k1], self.a[k2])
        end
    end
    self.lower = function(k1, k2)
        return not self.upper(k1, k2)
    end
    return self
end

function Heap:count()
    return #self.a
end

function Heap:_swap(k1, k2)
    local old_k1 = self.a[k1]
    self.a[k1] = self.a[k2]
    self.a[k2] = old_k1
end

function Heap:upheap(newk)
    local ku = math.floor(newk / 2)
    local k = newk
    while ku > 0 and self.lower(ku, k) do
        self:_swap(ku, k)
        k = math.floor(k/2)
        ku = math.floor(ku/2)
    end
end

function Heap:insertq(e)
    table.insert(self.a, e)
    self:upheap(#self.a)
end

function Heap:downheap(newk)
    local k = newk
    while k <= math.floor(#self.a/2) do
        local kdl = k*2
        local kdr = kdl + 1
        local kd
        if kdr <= #self.a and self.lower(kdl, kdr) then
            kd = kdr
        else
            kd = kdl
        end
        if self.upper(k, kd) then
            break
        end
        self:_swap(k, kd)
        k = kd
    end
end

function Heap:top()
    assert(#self.a >= 1)
    return self.a[1]
end

function Heap:remove_top()
    assert(#self.a >= 1)
    local v = self.a[1]
    self:_swap(1, #self.a)
    table.remove(self.a)
    self:downheap(1)
    return v
end

----
local N, M = io.read("*n", "*n")
local jobs_of_a = {}
for i=1, 100000 do
    jobs_of_a[i] = {}
end
for i=1, N do
    local a, b = io.read("*n", "*n")
    table.insert(jobs_of_a[a], b)
end
local q = Heap.new(function (v1, v2)
    return v1 > v2
end)
local ans = 0
for a=1,M do
    local day = M + 1 - a
    assert(day >= 1)
    for k,v in ipairs(jobs_of_a[a]) do
        q:insertq(v)
    end
    if q:count() > 0 then
        local job = q:remove_top()
        ans = ans + job
    end
end
print(ans)