#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("rucsac.in");
ofstream fout ("rucsac.out");
struct ob{
int g;
int val;
};
int main()
{
int n, greutate;
vector<ob> obiecte;
fin>>n>>greutate;
ob temp;
for(int i=0;i<n;i++)
{
fin>>temp.g>>temp.val;
obiecte.push_back(temp);
}
sort(obiecte.begin(), obiecte.end(), [](ob a, ob b) {return a.val>b.val;});
int gTotal=0, profit=0;
for(auto x:obiecte){
if(gTotal+x.g <= greutate){
profit+=x.val;
gTotal+=x.g;
}
else break;
}
cout<<profit;
fout<<profit;
return 0;
}