#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1E5+7;
struct stu{
	ll a,b;
	bool friend operator<(const stu &x,const stu &y){
		if(x.b!=y.b) return x.b>y.b;
		return x.a>y.a; 
	}
}arr[N];

int main(){
	ll n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&arr[i].a,&arr[i].b);
	}
	
	sort(arr+1,arr+1+n);
	int pos=1;
	ll ans=0;
	for(int i=1;i<=m&&pos<=n;i++){
		ll dx=arr[pos].a;
		ll dy=arr[pos].b;
		if(i+dx<=m+1){
			ans+=dy;
			pos++;
		}
		else {
			while(pos<=n&&i+arr[pos].a>m+1){
				pos++;
			}
			if(pos<=n){
				ans+=arr[pos].b;
				pos++;
			}
		}
	}
	cout<<ans<<endl;
	
	
	return 0;
}