#include <bits/stdc++.h>
using namespace std;
const int N=30000+5;
struct sdf{
bool ok;
int pt;
}p[1005][1005];
int f[N]={0};
int w[N],v[N],s[N]={0},ne=0;
int main(){
freopen ("delicious.in","r",stdin);
freopen ("delicious.out","w",stdout);
int n,m;
cin>>n>>m;
for (int i=1;i<=n;i++){
int a,b;
scanf("%d%d",&a,&b);
if (p[a][b].ok==0){
w[++ne]=a;
v[ne]=b;
s[ne]++;
p[a][b].pt=ne;
}
else{
s[p[a][b].pt]++;
}
}
for (int i=1;i<=ne;i++){
int mx=-1;
for (int j=0;(1<<j)<s[i];j++){
mx=j;
for (int k=m;k>=w[i]*(1<<j);j--){
f[k]=max(f[k],f[k-w[i]*(1<<j)]+v[i]*(1<<j));
}
}
int x;
if (mx==-1)x=s[i];
else x=s[i]-(1<<mx);
for (int j=m;j>=w[i]*x;j--){
f[j]=max(f[j],f[j-w[i]*x]+v[i]*x);
}
}
cout<<f[m]<<endl;
return 0;
}