#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
struct nod
{
	int x,y;
}line[maxn];
bool cmp (nod a,nod b)
{
	return a.x<b.x;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&line[i].x,&line[i].y);
	}
	sort(line,line+n,cmp);
	int sum=0;
	int ans=0;
	priority_queue<int> q;
	for(int i=1;i<=m;i++)
	{
		while(line[ans].x<=i&&ans<n)
		{
			q.push(line[ans].y);
			ans++;
		}
		if(q.empty())
		{
			continue;
		}
		sum+=q.top();
		q.pop();
	}
	printf("%d\n",sum);
	
	
	
	return 0;
	
}