#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;
int main() {
// cout << setprecision(10);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, m;
cin >> n >> m;
pair<ll, ll> a[n];
for (int i = 0; i < n; i++) {
cin >> a[i].second >> a[i].first;
}
ll ans = 0;
sort(a, a + n, greater<pair<ll, ll>>());
int d = 0;
for (auto e : a) {
if (d + e.second <= m) {
d++;
ans += e.first;
}
}
cout << ans;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nIGludAojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIG1vZCAxMDAwMDAwMDA3CiNkZWZpbmUgcGkgMy4xNDE1OTI2NTM1ODk3OTMKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgppbnQgbWFpbigpIHsKLy8gICAgY291dCA8PCBzZXRwcmVjaXNpb24oMTApOwogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOwogICAgY291dC50aWUoTlVMTCk7CgogICAgbGwgbiwgbTsKICAgIGNpbiA+PiBuID4+IG07CiAgICBwYWlyPGxsLCBsbD4gYVtuXTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgY2luID4+IGFbaV0uc2Vjb25kID4+IGFbaV0uZmlyc3Q7CiAgICB9CgogICAgbGwgYW5zID0gMDsKICAgIHNvcnQoYSwgYSArIG4sIGdyZWF0ZXI8cGFpcjxsbCwgbGw+PigpKTsKICAgIGludCBkID0gMDsKCiAgICBmb3IgKGF1dG8gZSA6IGEpIHsKICAgICAgICBpZiAoZCArIGUuc2Vjb25kIDw9IG0pIHsKICAgICAgICAgICAgZCsrOwogICAgICAgICAgICBhbnMgKz0gZS5maXJzdDsKICAgICAgICB9CgogICAgfQoKCiAgICBjb3V0IDw8IGFuczsKCgoKCgoKfQo=