#include <stdio.h>
#include <vector>
#include <queue>

#define pb push_back

using namespace std;

int main() {
	int n, m, a, b, ans = 0;
	vector<int> v[100010];
	priority_queue<int> pq;
	scanf("%d %d", &n, &m);
	while (n--) {
		scanf("%d %d", &a, &b);
		v[a].pb(b);
	}
	for (int i = 1; i <= m; i++) {
		for (int j = 0; j < (int) v[i].size(); j++)
			pq.push(v[i][j]);
		if (pq.size()) {
			ans += pq.top();
			pq.pop();
		}
	}
	printf("%d\n", ans);
	return 0;
}