#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

priority_queue<ll>Q;
vector<ll> v[100010];
int main(){
  ll n,m; cin>>n>>m;
  for(int i=0;i<n;i++){
    ll a,b; cin>>a>>b;
    v[a].push_back(b);
  }
  ll ans=0;
  for(int i=1;i<=m;i++){
    for(auto t:v[i])Q.push(t);
    if(!Q.empty()){
      ans+=Q.top();
      Q.pop();
    }
  }
  cout<<ans<<endl;
  return 0;
}
      
  
  