#include<bits/stdc++.h>
using namespace std;
vector<int>ve[100005];
int main()
{
	int n,m;
	int a,b;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		if(a>m)	continue;
		ve[m-a+1].push_back(b);
	}
	priority_queue<int>q;
	int sum=0;
	for(int i=m;i>=1;i--)
	{
		for(int v:ve[i])
		q.push(v);
		if(!q.empty())
		{
			sum+=q.top();
			q.pop();
		}
	}
	cout<<sum;
	return 0;
}