Array.prototype.insertOrderedDesc = function(item) {
	//if(this.length == 0) { this.push(item); return; }
	var range = Math.floor(this.length / 2);
	var dir = 1;
	var index = 0;
	while(range > 1) {
		index += dir * range;
      	var sub = this[index] - item;
		if(sub > 0) { dir = 1;}
		else if(sub < 0) { dir = -1; } else {
			this.splice(index, 0, item); return;
		}
		range = Math.floor(range / 2)
	}
	for(;0 <= index && index < this.length; index += dir) {
		if(dir * (this[index] - item) < 0) break;
	}	
	this.splice(index + (dir < 0 ? 1 : 0), 0, item);
};

var input = require('fs').readFileSync('/dev/stdin', 'utf8').split("\n").map((s)=>{return s.split(" ");});
var N = input[0][0]-0;
var Days = input[0][1]-0;
input.shift();

var works = new Array(Days);
input.forEach((item) => {
	var DFI = item[0]-0;
	if(works[DFI] == undefined) works[DFI] = [];
	works[DFI].push(item[1]-0);
});

var G = [];
var D = 1;
var Gain = 0;

var insertG = (income) => {
	var index = 0;
	for(; index < G.length; index++) {
		if(G[index] < income) break;
	}
	G.splice(index, 0, income);
};

for(;D <= Days; D++) {
	if(works[D] !== undefined) {
		works[D].forEach((income) => { G.insertOrderedDesc(income); });
	}
	if(G.length > 0) {
		Gain += G[0];
		G.shift();
	}
}
console.log(Gain);
