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

int main() {
  long long n,m;
  cin >> n >> m;

  map<int,vector<int>> mp;

  int a,b;
  for(int i=0;i<n;i++){
    cin >> a >> b;
    mp[a].push_back(b);
  }
  int ans = 0;
  priority_queue<int> q;
  for(int i=1;i<=m;i++){
    for(int x : mp[i]){
      q.push(x);
    }
    if(q.size() == 0){
      continue;
    }else{
      ans+=q.top();
      q.pop();
    }
  }
  cout << ans;
}