#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <cmath>
using namespace std;
vector<int> adj[55];
bool vis[55];
void dfs(int node){
    if(vis[node]) return;
    vis[node]= true;
    for(int x:adj[node]){
        if(!vis[x]) dfs(x);
    }
}


int main() {
    vector<pair<int,int>> a;
    int days,m,x,y,total=0;
    cin >>days>>m;
   int pointer=days-1;
    for(int i=0;i<days;i++){
        cin >>x>>y;
        a.push_back(make_pair(y,x));
    }
    sort(a.begin(),a.end());
    while(m>0&& pointer>=0){
        if(a[pointer].second <=m){
            total+=a[pointer].first;
            m--;
        }
        pointer--;
    }
    cout <<total<<"\n";
    return 0;
}