#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node{
	int x,y;
}num[1000];
bool cmp(node a,node b)
{
	if(a.x==b.x)
		return a.y>b.y;
	else
		return a.x>b.x;
}
int main()
{
	int n,m;
	ll ans=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		scanf("%d %d",&num[i].x,&num[i].y);
	sort(num,num+n,cmp);
	for(int i=0;i<n;i++)
	{
		if(num[i].x<=m)
		{
			ans+=num[i].y;
			m--;
		}
		if(m==0)
			break;
	}
	cout<<ans;
	return 0;
}