#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
	ll N,M;
	cin >> N >> M;
	vector<ll> v[100005];
	rep(i,N){
		ll x,y;
		cin >> x >> y;
		v[x].push_back(y);
	}
	
	priority_queue<ll> q;
	ll ans = 0;
	for (int i = M-1; i >= 0 ; --i) {
		for (auto u: v[M-i]){
			q.push(u);
		}
		if(!q.empty()) {
			ans += q.top();
			q.pop();
		}
	}
	
	cout << ans << endl;
    return 0;
}