
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
typedef long long ll;
vector<int> ve[N]; 
int main(){ 
	int n,m;
	cin>>n>>m;
	int a,b;
	priority_queue<int> q;
	ll earn=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		if(a>m) continue; 
		ve[m-a+1].push_back(b); 
	}
	for(int i=m;i>=1;i--)
	{
		for(int v:ve[i]) q.push(v);
		if(!q.empty())
		{
			earn+=q.top();
			q.pop();			
		}
	}
	cout<<earn<<endl;
	return 0;
}
