stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>

const int INF = 1e9;

const int MOD = 1e9+7;

const long long LINF = 1e18;

#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define rep(i,n) for(int i=0;i<(n);++i)

#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

typedef long long ll;

using namespace std;

typedef pair<ll, ll> P;



int main(int argc, char const *argv[]) {

    int n,m;cin>>n>>m;

    vector<vector<int>> x(114514);

    rep(i,n) {

        int a,b;cin>>a>>b;

        x[a].push_back(b);

    }



    priority_queue<ll> pq;

    ll ans = 0;



    for (int i = 1; i <= m; ++i) {

        for (auto &&e: x[i]) pq.push(e);

        if (!pq.empty()) ans += pq.top(), pq.pop();

    }



    cout << ans << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.8889046843237x):
#include <bits/stdc++.h>

const int INF = 1e9;

const int MOD = 1e9+7;

const long long LINF = 1e18;

#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define rep(i,n) for(int i=0;i<(n);++i)

#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

typedef long long ll;

using namespace std;

typedef pair<ll, ll> P;



template<typename T>

void print(const vector<T> &x) {

    int n = x.size();

    rep(i,n) {

        cout << x[i];

        if (i!=n-1) cout<<" ";

        else cout << endl;

    }

}



template<typename T>

void print(const vector<vector<T>> &x) {

    int n = x.size();

    rep(i,n) {

        rep(j,x[i].size()) {

            cout << x[i][j] << " ";

        }

        cout << endl;

    }

}



template<typename T>

void print(const vector<T> &x, int n) {

    rep(i,n) {

        cout << x[i];

        if (i!=n-1) cout<<" ";

        else cout << endl;

    }

}



template<typename T>

void print(const vector<vector<T>> &x, int n, int m) {

    rep(i,n) {

        rep(j,m) {

            cout << x[i][j] << " ";

        }

        cout << endl;

    }

}



template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



void input_init() {

    cin.tie(0); ios::sync_with_stdio(false);

}



int main(int argc, char const *argv[]) {

    int n,m; cin>>n>>m;

    priority_queue<ll> pq;

    map<ll,vector<ll>> mp;

    ll ans = 0;

    rep(i,n) {

        ll a,b; cin>>a>>b;

        mp[a].push_back(b);

    }



    for (int i = m-1; i >= 0; --i) {

        int day = m-i;

        for (auto &&e: mp[day]) {

            pq.push(e);

        }

        if (pq.empty()) continue;

        ans += pq.top();

        pq.pop();

    }



    cout << ans << '\n';

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

const int INF = 1e9;

const int MOD = 1e9+7;

const long long LINF = 1e18;

#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define rep(i,n) for(int i=0;i<(n);++i)

#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

typedef long long ll;

using namespace std;

typedef pair<ll, ll> P;



int main(int argc, char const *argv[]) {

    int n,m;cin>>n>>m;

    vector<vector<int>> x(114514);

    rep(i,n) {

        int a,b;cin>>a>>b;

        x[a].push_back(b);

    }



    priority_queue<ll> pq;

    ll ans = 0;



    for (int i = 1; i <= m; ++i) {

        for (auto &&e: x[i]) pq.push(e);

        if (!pq.empty()) ans += pq.top(), pq.pop();

    }



    cout << ans << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.8887793992221855x):
#include <bits/stdc++.h>

const int INF = 1e9;

const int MOD = 1e9+7;

const long long LINF = 1e18;

#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define rep(i,n) for(int i=0;i<(n);++i)

#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

typedef long long ll;

using namespace std;

typedef pair<ll, ll> P;



template<typename T>

void print(const vector<T> &x) {

    int n = x.size();

    rep(i,n) {

        cout << x[i];

        if (i!=n-1) cout<<" ";

        else cout << endl;

    }

}



template<typename T>

void print(const vector<vector<T>> &x) {

    int n = x.size();

    rep(i,n) {

        rep(j,x[i].size()) {

            cout << x[i][j] << " ";

        }

        cout << endl;

    }

}



template<typename T>

void print(const vector<T> &x, int n) {

    rep(i,n) {

        cout << x[i];

        if (i!=n-1) cout<<" ";

        else cout << endl;

    }

}



template<typename T>

void print(const vector<vector<T>> &x, int n, int m) {

    rep(i,n) {

        rep(j,m) {

            cout << x[i][j] << " ";

        }

        cout << endl;

    }

}



template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



void input_init() {

    cin.tie(0); ios::sync_with_stdio(false);

}



int main(int argc, char const *argv[]) {

    int n,m; cin>>n>>m;

    map<ll, vector<ll>> mp;

    priority_queue<ll> pq;

    rep(i,n) {

        ll a,b;

        cin>>a>>b;

        mp[a].push_back(b);

    }

    ll ans = 0;



    for (int i = m-1; i >= 0; --i) {

        for (auto &&e: mp[m-i]) {

            pq.push(e);

        }

        if (pq.empty()) continue;

        ll x = pq.top();pq.pop();

        ans += x;

    }



    cout << ans << '\n';

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

typedef long long LL;

typedef long double LD;

typedef unsigned long long ULL;



#ifdef _LOCAL

struct Tester {

    Tester() { freopen("sample.in", "r", stdin); }

    ~Tester() { fprintf(stderr, "\nTime: %d ms\n", int(1000.0 * clock() / CLOCKS_PER_SEC)); }

} _tester;

#endif



const int INF = 0x3F3F3F3F;

const LL INFLL = 0x3F3F3F3F3F3F3F3FLL;

const int N = 1e5 + 10;

const int Q = 1e5 + 10;



vector<int> v[N];



int main() {

    int n, m;

    cin >> n >> m;

    for (int i = 1; i <= n; ++i) {

        int time, reward;

        cin >> time >> reward;

        v[time].push_back(reward);

    }

    priority_queue<int> heap;

    LL res = 0;

    for (int i = 1; i <= m; ++i) {

        for (int val : v[i]) heap.push(val);

        if (!heap.empty()) {

            res += heap.top();

            heap.pop();

        }

    }

    cout << res;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.5722956493692846x):
#include <bits/stdc++.h>



using namespace std;

typedef long long LL;

typedef long double LD;

typedef unsigned long long ULL;



#ifdef _LOCAL

struct Tester {

    Tester() { freopen("sample.in", "r", stdin); }

    ~Tester() { fprintf(stderr, "\nTime: %d ms\n", int(1000.0 * clock() / CLOCKS_PER_SEC)); }

} _tester;

#endif



const int INF = 0x3F3F3F3F;

const LL INFLL = 0x3F3F3F3F3F3F3F3FLL;

const int N = 2550;



struct aP

{

    int a, b;

    aP(){}

    aP(int a, int b):a(a), b(b){}

    bool operator < (const aP &c) const{

        if(a == c.a) return b > c.b;

        return a > c.a; 

    }

};



struct bP

{

    int a, b;

    bP(){}

    bP(int a, int b):a(a), b(b){}

    bool operator < (const bP &c) const{

        if(b == c.b) return a > c.a;

        return b > c.b; 

    }

};



priority_queue<aP> input;

priority_queue<bP> already;



int main() {

    int n, m;

    scanf("%d%d", &n, &m);

    for(int i = 1; i <= n; i ++){

        int a, b;

        scanf("%d%d", &a, &b);

        input.push(aP(m - a, b));

    }

    while(!input.empty()){

        if(input.top().a >= (int)already.size()){

            // printf("[%d,%d]\n", input.top().a, input.top().b);

            already.push(bP(input.top().a, input.top().b));

        }else if((int)already.size() - 1 >= 0 && input.top().a == (int)already.size() - 1 && input.top().b > already.top().b){

            // printf("[%d,%d]->[%d,%d]\n", already.top().a, already.top().b, input.top().a, input.top().b);

            already.pop();

            already.push(bP(input.top().a, input.top().b));

        }

        input.pop();

    }

    LL ans = 0;

    while(!already.empty()){

        ans += 1LL * already.top().b;

        already.pop();

    }

    printf("%lld\n", ans);

    return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;

typedef long long LL;

typedef long double LD;

typedef unsigned long long ULL;



#ifdef _LOCAL

struct Tester {

    Tester() { freopen("sample.in", "r", stdin); }

    ~Tester() { fprintf(stderr, "\nTime: %d ms\n", int(1000.0 * clock() / CLOCKS_PER_SEC)); }

} _tester;

#endif



const int INF = 0x3F3F3F3F;

const LL INFLL = 0x3F3F3F3F3F3F3F3FLL;

const int N = 1e5 + 10;

const int Q = 1e5 + 10;



vector<int> v[N];



int main() {

    int n, m;

    cin >> n >> m;

    for (int i = 1; i <= n; ++i) {

        int time, reward;

        cin >> time >> reward;

        v[time].push_back(reward);

    }

    priority_queue<int> heap;

    LL res = 0;

    for (int i = 1; i <= m; ++i) {

        for (int val : v[i]) heap.push(val);

        if (!heap.empty()) {

            res += heap.top();

            heap.pop();

        }

    }

    cout << res;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.576730461081548x):
#include <algorithm>

#include <cstdio>

#include <cstring>

#include <iostream>

using namespace std;

using LL = long long;



const int N = 1e5 + 10;



struct Node {

    int w, t;



    bool operator<(const Node &b) const {

        return w > b.w;

    }

} a[N];



int fa[N];



void init(int n) {

    for (int i = 0; i <= n; ++i) fa[i] = i;

}



int find(int x) {

    return fa[x] == x ? x : fa[x] = find(fa[x]);

}



int main() {

#ifdef _LOCAL

    freopen("sample.in", "r", stdin);

#endif

    int n, m;

    scanf("%d%d", &n, &m);

    int Max = 0, tot = 0;

    for (int i = 1; i <= n; ++i) {

        int t, w;

        scanf("%d%d", &t, &w);

        t = m - t + 1;

        if (t >= 1) a[++tot] = {w, t};

        if (a[tot].t > Max) Max = a[tot].t;

    }

    n = tot;

    init(Max);

    sort(a + 1, a + n + 1);

    LL ans = 0;

    for (int i = 1; i <= n; ++i) {

        int pos = find(fa[a[i].t]);

        if (pos > 0) {

            fa[pos] = find(fa[pos] - 1);

            // printf("[%d,%d]\n", m - a[i].t + 1, a[i].w);

            ans += a[i].w;

        }

    }

    printf("%lld\n", ans);

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<queue>



using namespace std;



vector<int>ve[120000];



int main(){

//	ios::sync_with_stdio(false);

//	cin.tie(0);cout.tie(0);

	int n,k;

	cin>>n>>k;

	int x,y;

	for(int i=0;i<n;i++){

		cin>>x>>y;

		if(x>k) continue;

		int tt=k-x+1;

		ve[tt].push_back(y);

	}

	

	priority_queue<int>q;

	int ans=0;

	for(int i=k;i>=1;i--){

		for(int j=0;j<ve[i].size();j++) q.push(ve[i][j]);

		if(!q.empty()){

			ans+=q.top();

			q.pop();	

		}

	}

	cout<<ans<<"\n";

	

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 1.1391377925576103x):
#include <bits/stdc++.h>

 

using namespace std;

 

const int maxn=1e5+10;

const int inf=0x3f3f3f3f;

 

typedef long long ll;

 

vector<int> ve[maxn];//vector最好定义在外面，不然可能爆栈

 

int main()

{

//	freopen("input.txt","r",stdin);

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	

	int n,k;

	cin>>n>>k;

	int a,b;

	for(int i=0;i<n;i++)

	{

		cin>>a>>b;

		if(a>k) continue;//要有这个条件，不然下面的vector可能会成负值

		ve[k-a+1].push_back(b);//表示只能在m-a+1天或者之前做

	}

	priority_queue<int> q;

	int earn=0;

	for(int i=k;i>=1;i--)

	{

		for(int v:ve[i]) q.push(v);

		if(!q.empty())

		{

			earn+=q.top();

			q.pop();

		}

	}

	cout<<earn;

	

	

	return 0;

 }
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<queue>

typedef long long ll;

using namespace std;

const int maxn = 1e5+10;

vector<int>ve[maxn];

//如果想要队列 从小到大排列 



int main()

{

	ios::sync_with_stdio(0);

	cin.tie(0);

	int n,m;

	cin>>n>>m;

	int a,b;

	for(int i=1;i<=n;i++)

	{

		cin>>a>>b;

		if(a<=m)

		{

			ve[m-a+1].push_back(b);

		}

	}

	ll ans = 0;

	priority_queue<int>que;//队列从小到大飘排列 

	for(int i=m;i>=1;i--)

	{

		for(auto v:ve[i])

			que.push(v);

		if(!que.empty())

		{

			ans+=que.top();	

			que.pop();

		}	

	}

	cout<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.538235002181995x):
#include <bits/stdc++.h>

using namespace std;



int main() {

	int n, m;

	cin >> n >> m;

	multiset<int, greater<int> > s;

	vector<pair<int, int>> v;

	for (int i = 0; i < n; ++i) {

		int A, B;

		cin >> A >> B;

		v.push_back( { A, B });



	}

	int j = 0;

	sort(v.begin(), v.end());

	long long res = 0;

	for (int i = 1; i <= m; i++) {

		while (j < n && v[j].first == i) {

			s.insert(v[j].second);

			j++;

		}

		if (s.size()) {

			res += *s.begin();

			s.erase(s.begin());

		}

	}

	cout << res;

	return 0;

}

/*

 *

 * 1 4

 * 1 4

 * 1 2

 * 2 3

 * 2 2

 * 2 1

 * 3 3 j

 * 3 4

 * 3 1

 1=>  4 2

 2=>

 3=> 3 4 1 2 3 1 2

 4+4+4

 */
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<queue>



using namespace std;



vector<int>ve[120000];



int main(){

//	ios::sync_with_stdio(false);

//	cin.tie(0);cout.tie(0);

	int n,k;

	cin>>n>>k;

	int x,y;

	for(int i=0;i<n;i++){

		cin>>x>>y;

		if(x>k) continue;

		int tt=k-x+1;

		ve[tt].push_back(y);

	}

	

	priority_queue<int>q;

	int ans=0;

	for(int i=k;i>=1;i--){

		for(int j=0;j<ve[i].size();j++) q.push(ve[i][j]);

		if(!q.empty()){

			ans+=q.top();

			q.pop();	

		}

	}

	cout<<ans<<"\n";

	

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 4.022396788026073x):
#include <bits/stdc++.h>

using namespace std;



int main() {

	int n, m;

	cin >> n >> m;

	multiset<int, greater<int> > s;

	vector<pair<int, int>> v;

	for (int i = 0; i < n; ++i) {

		int A, B;

		cin >> A >> B;

		v.push_back( { A, B });



	}

	int j = 0;

	sort(v.begin(), v.end());

	long long res = 0;

	for (int i = 1; i <= m; i++) {

		while (j < n && v[j].first == i) {

			s.insert(v[j].second);

			j++;

		}

		if (s.size()) {

			res += *s.begin();

			s.erase(s.begin());

		}

	}

	cout << res;

	return 0;

}

/*

 *

 * 1 4

 * 1 4

 * 1 2

 * 2 3

 * 2 2

 * 2 1

 * 3 3 j

 * 3 4

 * 3 1

 1=>  4 2

 2=>

 3=> 3 4 1 2 3 1 2

 4+4+4

 */
// Slower C++ solution:
#include <bits/stdc++.h>

 

using namespace std;

 

const int maxn=1e5+10;

const int inf=0x3f3f3f3f;

 

typedef long long ll;

 

vector<int> ve[maxn];//vector最好定义在外面，不然可能爆栈

 

int main()

{

//	freopen("input.txt","r",stdin);

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	

	int n,k;

	cin>>n>>k;

	int a,b;

	for(int i=0;i<n;i++)

	{

		cin>>a>>b;

		if(a>k) continue;//要有这个条件，不然下面的vector可能会成负值

		ve[k-a+1].push_back(b);//表示只能在m-a+1天或者之前做

	}

	priority_queue<int> q;

	int earn=0;

	for(int i=k;i>=1;i--)

	{

		for(int v:ve[i]) q.push(v);

		if(!q.empty())

		{

			earn+=q.top();

			q.pop();

		}

	}

	cout<<earn;

	

	

	return 0;

 } 


// Faster C++ solution for the same problem (measured speedup: 3.531088876434276x):
#include <bits/stdc++.h>

using namespace std;



int main() {

	int n, m;

	cin >> n >> m;

	multiset<int, greater<int> > s;

	vector<pair<int, int>> v;

	for (int i = 0; i < n; ++i) {

		int A, B;

		cin >> A >> B;

		v.push_back( { A, B });



	}

	int j = 0;

	sort(v.begin(), v.end());

	long long res = 0;

	for (int i = 1; i <= m; i++) {

		while (j < n && v[j].first == i) {

			s.insert(v[j].second);

			j++;

		}

		if (s.size()) {

			res += *s.begin();

			s.erase(s.begin());

		}

	}

	cout << res;

	return 0;

}

/*

 *

 * 1 4

 * 1 4

 * 1 2

 * 2 3

 * 2 2

 * 2 1

 * 3 3 j

 * 3 4

 * 3 1

 1=>  4 2

 2=>

 3=> 3 4 1 2 3 1 2

 4+4+4

 */
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<queue>



using namespace std;



vector<int>ve[120000];



int main(){

//	ios::sync_with_stdio(false);

//	cin.tie(0);cout.tie(0);

	int n,k;

	cin>>n>>k;

	int x,y;

	for(int i=0;i<n;i++){

		cin>>x>>y;

		if(x>k) continue;

		int tt=k-x+1;

		ve[tt].push_back(y);

	}

	

	priority_queue<int>q;

	int ans=0;

	for(int i=k;i>=1;i--){

		for(int j=0;j<ve[i].size();j++) q.push(ve[i][j]);

		if(!q.empty()){

			ans+=q.top();

			q.pop();	

		}

	}

	cout<<ans<<"\n";

	

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 1.1363782120773571x):
#include <bits/stdc++.h>

using namespace std;



int main()

{

    int n,m;

    cin>>n>>m;

    long long sum=0;

    vector<int> v[100001];

    priority_queue<int> pq ;

    for(int i=0 ; i<n ; i++)

    {

        int r , d ;

        cin>>d>>r;

        v[d].push_back(r);

    }

    for(int i=1 ; i<=m  ; i++)

    {

        for(int j=0 ; j<v[i].size() ; j++)

        {

           pq.push( v[i][j] );

        }

        if( pq.size() !=0 ){

        sum+=pq.top();

        pq.pop();}

    }

    cout<<sum<<endl;

    return 0;

}
// Slower C++ solution:
#include<iostream>

#include<algorithm>

#include<queue>

typedef long long ll;

using namespace std;

const int maxn = 1e5+10;

vector<int>ve[maxn];

//如果想要队列 从小到大排列 



int main()

{

	ios::sync_with_stdio(0);

	cin.tie(0);

	int n,m;

	cin>>n>>m;

	int a,b;

	for(int i=1;i<=n;i++)

	{

		cin>>a>>b;

		if(a<=m)

		{

			ve[m-a+1].push_back(b);

		}

	}

	ll ans = 0;

	priority_queue<int>que;//队列从小到大飘排列 

	for(int i=m;i>=1;i--)

	{

		for(auto v:ve[i])

			que.push(v);

		if(!que.empty())

		{

			ans+=que.top();	

			que.pop();

		}	

	}

	cout<<ans<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 3.4835642976421775x):
#include <bits/stdc++.h>



using namespace std;



typedef long long          ll;

typedef unsigned long long ull;

typedef vector<int>	       vi;

typedef vector<bool>       vb;

typedef map<int, int>      mii;

typedef pair<int, int>     ii;



#define INF                0x3f3f3f3f

#define INFLL              0x3f3f3f3f3f3f3f3f

#define each(x, s)         for(auto& x : s)

#define loop(x)	           for(int i = 0;i < x;i++)

#define vloop(v, x)        for(int v = 0;v < x;v++)

#define avg(l, r)          l + (r - l) / 2

#define iter(a)            a.begin(), a.end()

#define riter(a)           a.rbegin(), a.rend()

#define endl               "\n"



const ll mod = 1000000007;



int main() {

	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);



	int n, m;

	cin >> n >> m;

	vector<ii> ps;

	int a, b;

	loop(n) {

		cin >> a >> b;

		ps.emplace_back(a, b);

	}

	sort(iter(ps));

	int ans = 0;

	priority_queue<int> q;

	for (int i = 1, j = 0;i <= m and (j < n or !q.empty());i++) {

		while (j < n and ps[j].first <= i) q.push(ps[j].second), j++;

		if (!q.empty()) {

			ans += q.top();

			q.pop();

		}

	}

	cout << ans << endl;

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<vector>

#include<queue>



using namespace std;



vector<int>ve[120000];



int main(){

//	ios::sync_with_stdio(false);

//	cin.tie(0);cout.tie(0);

	int n,k;

	cin>>n>>k;

	int x,y;

	for(int i=0;i<n;i++){

		cin>>x>>y;

		if(x>k) continue;

		int tt=k-x+1;

		ve[tt].push_back(y);

	}

	

	priority_queue<int>q;

	int ans=0;

	for(int i=k;i>=1;i--){

		for(int j=0;j<ve[i].size();j++) q.push(ve[i][j]);

		if(!q.empty()){

			ans+=q.top();

			q.pop();	

		}

	}

	cout<<ans<<"\n";

	

	return 0;

} 

// Faster C++ solution for the same problem (measured speedup: 3.9602451033006467x):
#include <bits/stdc++.h>



using namespace std;



typedef long long          ll;

typedef unsigned long long ull;

typedef vector<int>	       vi;

typedef vector<bool>       vb;

typedef map<int, int>      mii;

typedef pair<int, int>     ii;



#define INF                0x3f3f3f3f

#define INFLL              0x3f3f3f3f3f3f3f3f

#define each(x, s)         for(auto& x : s)

#define loop(x)	           for(int i = 0;i < x;i++)

#define vloop(v, x)        for(int v = 0;v < x;v++)

#define avg(l, r)          l + (r - l) / 2

#define iter(a)            a.begin(), a.end()

#define riter(a)           a.rbegin(), a.rend()

#define endl               "\n"



const ll mod = 1000000007;



int main() {

	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);



	int n, m;

	cin >> n >> m;

	vector<ii> ps;

	int a, b;

	loop(n) {

		cin >> a >> b;

		ps.emplace_back(a, b);

	}

	sort(iter(ps));

	int ans = 0;

	priority_queue<int> q;

	for (int i = 1, j = 0;i <= m and (j < n or !q.empty());i++) {

		while (j < n and ps[j].first <= i) q.push(ps[j].second), j++;

		if (!q.empty()) {

			ans += q.top();

			q.pop();

		}

	}

	cout << ans << endl;

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

 

using namespace std;

 

const int maxn=1e5+10;

const int inf=0x3f3f3f3f;

 

typedef long long ll;

 

vector<int> ve[maxn];//vector最好定义在外面，不然可能爆栈

 

int main()

{

//	freopen("input.txt","r",stdin);

	ios::sync_with_stdio(false);

	cin.tie(0);

	cout.tie(0);

	

	int n,k;

	cin>>n>>k;

	int a,b;

	for(int i=0;i<n;i++)

	{

		cin>>a>>b;

		if(a>k) continue;//要有这个条件，不然下面的vector可能会成负值

		ve[k-a+1].push_back(b);//表示只能在m-a+1天或者之前做

	}

	priority_queue<int> q;

	int earn=0;

	for(int i=k;i>=1;i--)

	{

		for(int v:ve[i]) q.push(v);

		if(!q.empty())

		{

			earn+=q.top();

			q.pop();

		}

	}

	cout<<earn;

	

	

	return 0;

 } 


// Faster C++ solution for the same problem (measured speedup: 3.4765285895826894x):
#include <bits/stdc++.h>



using namespace std;



typedef long long          ll;

typedef unsigned long long ull;

typedef vector<int>	       vi;

typedef vector<bool>       vb;

typedef map<int, int>      mii;

typedef pair<int, int>     ii;



#define INF                0x3f3f3f3f

#define INFLL              0x3f3f3f3f3f3f3f3f

#define each(x, s)         for(auto& x : s)

#define loop(x)	           for(int i = 0;i < x;i++)

#define vloop(v, x)        for(int v = 0;v < x;v++)

#define avg(l, r)          l + (r - l) / 2

#define iter(a)            a.begin(), a.end()

#define riter(a)           a.rbegin(), a.rend()

#define endl               "\n"



const ll mod = 1000000007;



int main() {

	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);



	int n, m;

	cin >> n >> m;

	vector<ii> ps;

	int a, b;

	loop(n) {

		cin >> a >> b;

		ps.emplace_back(a, b);

	}

	sort(iter(ps));

	int ans = 0;

	priority_queue<int> q;

	for (int i = 1, j = 0;i <= m and (j < n or !q.empty());i++) {

		while (j < n and ps[j].first <= i) q.push(ps[j].second), j++;

		if (!q.empty()) {

			ans += q.top();

			q.pop();

		}

	}

	cout << ans << endl;

	return 0;

}