Problem: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.

You can take and complete at most one of these jobs in a day.

However, you cannot retake a job that you have already done.

Find the maximum total reward that you can earn no later than M days from today.

You can already start working today.

Constraints

* All values in input are integers.
* 1 \leq N \leq 10^5
* 1 \leq M \leq 10^5
* 1 \leq A_i \leq 10^5
* 1 \leq B_i \leq 10^4

Input

Input is given from Standard Input in the following format:


N M
A_1 B_1
A_2 B_2
\vdots
A_N B_N


Output

Print the maximum total reward that you can earn no later than M days from today.

Examples

Input

3 4
4 3
4 1
2 2


Output

5


Input

5 3
1 2
1 3
1 4
2 1
2 3


Output

10


Input

1 1
2 1


Output

0

Solution (in JAVA):

Solution:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	
	static final int MINUS_INF = -1001001001;

	public static void main(String[] args) {
		
		Main main = new Main();
		main.exec();
		
	}
	
	public void exec() {
		Scanner sc = new Scanner(System.in);
		String[] firstArr = sc.nextLine().split(" ");
		int n = Integer.parseInt(firstArr[0]);
		int m = Integer.parseInt(firstArr[1]);
		ArrayList<Arbeit> arbeitList = new ArrayList<>();
		for(int i = 0; i < n; i++) {
			String[] arbeitStrArr = sc.nextLine().split(" ");
			arbeitList.add(new Arbeit(Integer.parseInt(arbeitStrArr[1]), Integer.parseInt(arbeitStrArr[0])));
		}
		
		sc.close();
		
		Comparator<Arbeit> salaryComparator = Comparator.comparing(Arbeit::getSalary).reversed();
		Comparator<Arbeit> transferDateComparator = Comparator.comparing(Arbeit::getTransferDate).reversed();
		
		arbeitList.sort(transferDateComparator);
		arbeitList.sort(salaryComparator);
		
		int leafSize = 1;
		while(m+1 > leafSize) {
			leafSize *= 2;
		}
		int[] leafArr = new int[leafSize];
		for(int i = 0; i < leafSize ; i++) {
			if(i < m+1) {
				leafArr[i] = i;
			}else {
				leafArr[i] = MINUS_INF;
			}
		}
		
		int[] emptyScheList = makeSegmentTree(leafArr);
//		System.out.println(Arrays.toString(emptyScheList));
		
		int sumOfSalary = 0;
		
		for(Arbeit arbeit : arbeitList) {
			
			int transferDate = arbeit.getTransferDate();
			int choice = m - transferDate;
			
			int arbeitDay = getMax(emptyScheList, 0,choice+1, 0, 0, leafArr.length);
//			System.out.println(arbeitDay);
//			System.out.println(Arrays.toString(emptyScheList));
			
			if(arbeitDay == m) {
				return;
			}
			if(arbeitDay >= 0) {
				updateSegTree(emptyScheList, arbeitDay, MINUS_INF);
				sumOfSalary += arbeit.getSalary();
			}
		}
		System.out.println(sumOfSalary);
//		System.out.println(Arrays.toString(emptyScheList));
	}

	/**
	 * 0-n-1を葉に持つsegment木を作る
	 * @param intArr
	 * @param n
	 */
	public int[] makeSegmentTree(int[] leafArr) {
		
		int[] intArr = new int[leafArr.length*2 - 1];
		
		for(int i = leafArr.length - 1; i >= 0; i--) {
			int index;
			index = intArr.length - (leafArr.length - i);
			intArr[index] = leafArr[i];
		}
		
		int segN = (intArr.length + 1)/2;
		for(int i = segN -2; i >= 0; i--) {
			intArr[i] = Math.max(intArr[2*i + 1], intArr[2*i+2]);
		}
		return intArr;
	}
	
	public int getMax(int[] segTree, int a, int b, int k, int l, int r) {
		
		if(r <= a || b <= l) {
			return MINUS_INF;
		}
		
		if(a <= l && r <= b ) {
			return segTree[k];
		}
		
		return Math.max(getMax(segTree, a, b, 2*k+1,l, (l+r)/2) , getMax(segTree, a,b,2*k+2, (l+r)/2, r));
	}
	
	public void updateSegTree(int[] segTree, int pos, int value) {
		pos += (segTree.length + 1)/2 - 1;
		segTree[pos] = value;
		while(pos > 0) {
			pos = (pos - 1) / 2;
			segTree[pos] = Math.max(segTree[pos*2 +1], segTree[pos*2 +2]);
		}
	}
	
	public class Arbeit{
		int salary;
		int transferDate;
		
		public Arbeit(int salary, int transferDate){
			this.salary = salary;
			this.transferDate = transferDate;
		}
		
		public int getSalary() {
			return this.salary;
		}
		public int getTransferDate(){
			return this.transferDate;
		}
	}
}