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

var works = new Array(totaldays);
input.forEach((item) => {
	var DFI = item[0]-0;
	if(works[DFI] == undefined) works[DFI] = [];
	works[DFI].push(item[1]-0);
});
works.forEach((item) => {item.sort();});
var gain = 0;
var maxPayAtDay = (d) => {
	if(works[d] == undefined || works[d].length == 0) return 0;
	return works[d][0];
};
for(var day = totaldays; day >= 0; day--) {
	var maxpayday = 0;
	var maxpay = 0;
	for(var rdays = day; rdays >= 0; rdays--) {
		var thisMaxPay = maxPayAtDay(rdays);
		if(maxpay < thisMaxPay) {
			maxpayday = rdays;
			maxpay = thisMaxPay;
		}
	}
	if (maxpay > 0) {
		gain += maxpay;
		works[maxpayday].shift();
	}
}
cosole.log(gain);
