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.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;

    public static void main(String[] args) {
        int N = nint();
        int M = nint();
        List<Task> list = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            list.add(new Task(nint(), nint()));
        }
        
        Map<Integer, List<Task>> map = list.stream().collect(Collectors.groupingBy(e -> e.day));
        List<Integer> keys = new ArrayList<>(map.keySet());
        keys.sort((a, b) -> a-b);
        
        PriorityQueue<Task> q = new PriorityQueue<>((t1, t2) -> t2.reward - t1.reward);
        
        int ans = 0;
        for (int i = 1, keyIdx = 0; i <= M; i++) {
            if (keyIdx < keys.size()) {
                int key = keys.get(keyIdx);
                if (key <= i) {
                    keyIdx++;
                    map.get(key).forEach(t -> q.add(t));
                }
            }
            if (!q.isEmpty()) {
                Task polled = q.poll();
                ans += polled.reward;
            }
        }
        
        so.println(ans);
    }
    
    static class Task {
        int day;
        int reward;
        Task(int day, int reward) {
            this.day = day;
            this.reward = reward;
        }
        @Override
        public String toString() {
            return "[day = " + day + ", reward = " + reward + "]";
        }
    }

    private static int here(int i) {
        return (i+1)/2;
    }
    
    private static int there(int i) {
        return i/2;
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static String[] nstrs(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = nstr();
        return a;
    }

    private static char[][] nsToChars2D(int h, int w) {
        return nsToChars2D(h, w, 0);
    }

    private static char[][] nsToChars2D(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nsToChars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}