#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize("SEX_ON_THE_BEACH")	
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:36777216")

#define _CRT_SECURE_NO_WARNINGS

#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>//////////////
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define queuel queue<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(), v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for (auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for (int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for (int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for (int i = 0; i < n; ++i){int a; cin >> a; s.insert(a); }
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); srand(time(NULL))
#define sp system("pause")
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;//СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚СЂСџВ¦Р‚
					//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
//#define int ll
const int MAXN = 2e5 + 1;
const ll inf = 1e9;
const ld EPS = 1e-4;
const ld PI = acos(-1);
int mod = (int)998244353;
//const int MOD = 1000000007;
const int MOD9 = 1000000009;
const int a228 = 18;
const ll MOD = 1000000007;
const int maxelem = 12000000;
const int fsconst = 12000;
bool cmp(pair<int, int> a, pair<int, int> b)
{
	if (a.first == b.first) return a.second > b.second;
	return a.first < b.first;
}
vector<multiset<int>> t(4* MAXN);
vector<pair<int,int>> tmch(4 * MAXN);
void upd(int v, int l, int r, int ql, int qr, int x, int y)
{
	if (l >= qr || ql >= r) return;
	if (l >= ql && r <= qr)
	{
		if (x < 0)
		{
			if (!t[v].size()) return;
			t[v].erase(t[v].find(*t[v].rbegin()));
			tmch[v] = { (t[v].size() == 0 ? -228 : *t[v].rbegin()), l };
			return;
		}
		t[v].insert(y);
		tmch[v] = { *t[v].rbegin(), l };
		return;
	}
	upd(2 * v + 1, l, (l + r) / 2, ql, qr, x, y);
	upd(2 * v + 2, (l + r) / 2, r, ql, qr, x, y);
	tmch[v] = max(tmch[2 * v + 1], tmch[2 * v + 2]);
}
pair<int,int> get(int v, int l, int r, int ql, int qr)
{
	if (l >= qr || ql >= r) return { -228,228 };
	if (l >= ql && r <= qr)
	{
		return tmch[v];
	}
	auto g1 = get(2 * v + 1, l, (l + r) / 2, ql, qr);
	auto g2 = get(2 * v + 2, (l + r) / 2, r, ql, qr);
	return max(g1, g2);
}
signed main()
{
	fastio();
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i].first >> a[i].second;
	}
	sort(all(a), cmp);
	set<int> ok;
	for (int i = 0; i < m; ++i)
	{
		ok.insert(i);
	}
	for (auto i : a) upd(0, 0, 1e5 + 1, i.first, i.first + 1,1, i.second);
	int ans = 0;
	multiset<pair<int, int>> jopa;
	for (auto i : a) jopa.insert(i);
	for (int i = m - 1; i >= 0; --i)
	{
		auto j = get(0, 0, 1e5 + 1, 0, m - i + 1);
		if (j.first < 0) continue;
		ans += j.first;
		upd(0, 0, 1e5 + 1, j.second, j.second + 1, -228, 123);
	}
	cout << ans;
	//sp;
}

Measured memory_bytes: 58880