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

int main()
{
    int N, M; cin >> N >> M;
    vector<int> v[100001];
    for (int i=0; i<N; i++) {
        int A, B; cin >> A >> B;
      	v[A].push_back(B);
    }
  
    int ans = 0;
    priority_queue<int> pq;
    for (int i=1; i<=M; i++)
    {
        for (auto e : v[i]) pq.push(e);
   		if (! pq.empty()) {
          ans += pq.top();
          pq.pop();
        }
    }

    cout << ans << endl;
}