#include<bits/stdc++.h>
using namespace std;

int main (){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> v(100005);
    for(int i=0;i<n;i++){
        int d,val;
        cin>>d>>val;
        v[d].push_back(val);
    }
    long long int ans=0;
    priority_queue<int> q; 
    for(int i=1;i<=m;i++){
        for(int j=0;j<v[i].size();j++)  q.push(v[i][j]);
        if(!q.empty())  ans+=q.top(),q.pop();
    }
    cout<<ans;
    return 0;
}