////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                    //
//	                                      Created by Aeren                                            //
//                                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                    //
//                                                                                                    //
//                                              ______________                                        //
//             ++++++++++                ___----------------------__                                  //
//           +++`+``+`+`++++        ///``````````````````````````````\\\                              //
//           ++`+`+``+++`++++  /////```````````````````````````````````\\\                            //
//           +++`++`+`+``+++/////````````````````````````````````````````\\\                          //
//             +++`++`+``+///```````````|````````` ````````````````````````\\\                        //
//          ____++++/++++/`````````````/````````|````````|```````````````````\\                       //
//        /    / /|    //``````````````|````````|```````|`````````````````````\\                      //
//       |   /  //| ///````````/```````|```````||```````|````````|``````````````\\                    //
//        \ /_/ / |///.````````|``````/````````|````````|````````|````````.````` \                    //
//        /|\_|_/ |-...````````|``````|````````|`````````|`````.`|````````````````\                   //
//       / \__|__/--...````````|.````|````````:|````````|:`````::|::`````|`````````|                  //
//      /     /  /:...````````|/`    |        :|        :|       |```````|``++````++                  //
//      |    / //::...````````|      |        |:        :|       |       |```++``++||                 //
//     /    /  /-:-`..````````/    _.::::.    |         :       :        |``` `++``||                 //
//     |   /  --:-.`.-```````|            ``           `       `        `|```++``++`|                 //
//     |  /    /:-....```````|                                           |``++````++|                 //
//     | /     /-....````````|                              _.-:::.      |..````.`..|                 //
//     |/     /-.````````````.                                     `     .``````.`.`|\                //
//    /|      |-``````````````                    :'                    .|`````````.||                //
//   / |     `|.`````````````.                                         -|-|`````````\\                //
//  /  |     `|````.`````````-                                        --||`````````.|\\               //
//            |``````````````|::                                    :..-||`````````|``|               //
//			  \\`````````````|:::.        `...                    .\___/-|`````````|``|               //
//			  \\`````````````|::::-           `:::....           --::/:::|`````````.``\               //
//			   \\````````````|::::`|.                          .:::/:::::-|````````|``|               //
//      	    \```.````````|::::/|--.                     .-:/:::/:::::/````````//``\               //
//      	     \\`.````````-:::|`|-----              ..-:|:::/::::::::|-``/|````/  `\`              //
//      	      \`.````````-|:::\|-----`-.___......------/:::/::::::::|.`//|```/     \              //
//                 \\-```|\````|```\_________````__________/\---::::::::|                             //
//                  .\.``| \```|```....-.---`\`./:-:--...````\`.\\\:::::|                             //
//                  __\``|_/\``|------------:-\/-----::-..````\_________|__                           //
//                                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////////////////////

#include<bits/stdc++.h>
#include<chrono>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace chrono;
#define all(a) a.begin(), a.end()
#define sz(x) (int(x.size()))
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef vector<string> vs;
template<class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P){
	in >> P.first >> P.second;
	return in;
}
template<class T1, class T2>
ostream &operator<<(ostream &out, pair<T1, T2> &P){
	out << "(" << P.first << ", " << P.second << ")";
	return out;
}
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T>
ostream &operator<<(ostream &out, vector<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<pii> a(n);
	cin >> a;
	sort(all(a), greater<pii>());
	multiset<int, greater<int>> q;
	int res = 0;
	for(int i = m - 1; i >= 0; i --){
		while(!a.empty() && a.back().first == m - i){
			q.insert(a.back().second);
			a.pop_back();
		}
		if(!q.empty()){
			res += *q.begin();
			q.erase(q.begin());
		}
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 5632