#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, m; cin >> n >> m;
	map<int, vector<int> > can;
	for(int i = 0; i < n; i++){
		int a, b; cin >> a >> b;
		if(a > m) continue;
		can[a].push_back(b);
	}
	int ans = 0;
	multiset<int> vals;
	for(int i = 1; i <= m; i++){
		for(int v : can[i]) vals.insert(v);
		if(!vals.empty()){
			ans += *(--vals.end());
			vals.erase(--vals.end());
		}
	}
	cout << ans << endl;
	return 0;
}
