#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(),x.end()

int main(){
  ll n,m,ans=0;
  cin >> n >> m;
  vector<ll> a[200010];
  for(ll i=0;i<n;i++){
    ll x,y;
    cin >> x >> y;
    if(x>m) continue;
    a[x].push_back(y);
  }
  priority_queue<ll> pq;
  for(ll i=1;i<=m;i++){
    for(auto e: a[i]){
      pq.push(e);
    }
    if(!pq.empty()){
      ans += pq.top();
      pq.pop();
    }
  }
  cout << ans << endl;
}