#include<bits/stdc++.h>
#define FI first
#define SE second
using namespace std;

int n,m,a,b,ans;
pair<int,int> arr[100005];
priority_queue<int> PQ;

int main(){
	scanf("%d%d",&n,&m);
	for(int i =0;i<n;i++){
		scanf("%d%d",&a,&b);
		arr[i] = {a,b};
	}
	sort(arr,arr+n);
	int id = 0;
	for(int i =1;i<=m;i++){
		while(id<n && arr[id].FI==i){
			PQ.push(arr[id].SE);
			id++;
		}
		if(PQ.empty()) continue;
		ans+= PQ.top();
		PQ.pop();
	}
	
	printf("%d\n",ans);
	return 0;
}