#include<bits/stdc++.h>
using namespace std;
priority_queue<int> q;
struct node {
	int money;
	int day;
};
node a[300000];
bool cmp(node a,node b)
{
	return a.day<b.day;
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].day>>a[i].money;
	}
	sort(a,a+n,cmp);
	int ans=0;
	int x=0;
	for(int i=1;i<=m;i++)
	{
		while(a[x].day<=i&&x<n)
		
			q.push(a[x++].money);
			if(!q.empty())
			{
			ans=ans+q.top();
			q.pop();
		    }
	}
	cout<<ans<<endl;
	
}