// Arup Guha
// 6/1/2013
// Solution to 2013 KTH Challenge Problem F: Bank Queue

import java.util.*;

public class bank {

	public static void main(String[] args) {

		// Get input.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int t = stdin.nextInt();

		// Create and sort people.
		person[] list = new person[n];
		for (int i=0; i<n; i++) {
			int mym = stdin.nextInt();
			int myt = stdin.nextInt();
			list[i] = new person(mym, myt);
		}
		Arrays.sort(list);

		// Store money at each minute here.
		int[] money = new int[t+1];

		// Try to place each person.
		for (int i=0; i<n; i++) {

			// Due to bounds we can do this.
			for (int j=list[i].time; j>=0; j--) {
				if (money[j] == 0) {
					money[j] = list[i].money;
					break;
				}
			}
		}

		// Add up money from each minute.
		int res = 0;
		for (int i=0; i<=t; i++)
			res += money[i];

		// Ta da!
		System.out.println(res);
	}
}

class person implements Comparable<person> {

	public int money;
	public int time;

	public person(int m, int t) {
		money = m;
		time = t;
	}

	public int compareTo(person other) {
		if (this.money != other.money) return other.money - this.money;
		return this.time - other.time;
	}
}