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 = [0];
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) => { insertG(income); });
	}	
	Gain += G[0];
}
console.log(Gain);
