#include <bits/stdc++.h>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;

	vector<vector<int>> jb( M );
	for( int i = 0; i < N; ++i ) {
		int A, B;
		cin >> A >> B;

		if( A <= M ) {
			jb.at( M-A ).push_back( B );
		}
	}

	int result = 0;
	priority_queue<int> q;

	for( int i = M-1; i >= 0; --i ) {
		for( auto v: jb.at( i ) ) {
			q.push( v );
		}

		if( !q.empty() ) {
			result += q.top();
			q.pop();
		}
	}

	cout << result << endl;
}
