#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {
	// your code goes here
	
	int n,m;
	cin>>n>>m;
	
	vector<int>tasks[m+1];
	
	priority_queue<int,vector<int>> pq;
	
	for(int i=1;i<=n;i++){
		
		int a,b;
		cin>>a>>b;
		
		if(a<=m)
			tasks[a].push_back(b);
	
	}
	
	long long ans=0;
	
	for(int i=1;i<=m;i++){
		
		for(auto x:tasks[i]){
			pq.push(x);	
		}
		
		if(!pq.empty()){
			ans+=pq.top();
			pq.pop();
		}
	}
	
	cout<<ans<<endl;
	return 0;
}