#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
priority_queue<int>q;
int n,m,ans;
pair<int,int>a[maxn];
int main()
{
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=n;i++)
		scanf("%d%d",&a[i].first,&a[i].second);
	sort(a+1,a+n+1);
	int l=1;
	for(register int i=m;i>=1;i--)
	{
		while(l<=n && a[l].first+i-1<=m)
			q.push(a[l++].second);
		if(!q.empty())
		{
			ans+=q.top();
			q.pop();
		}
	}
	printf("%d",ans);
	return 0;
}