典型的0-1背包
#include <cstdio>
#include <cstring>
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
int n , m;
int f[1010];
int c[101] , w[101];
void ZeroOnePack(int cost , int weight) {
for(int i=m;i>=cost;i--)
f[i] = f[i] > f[i-cost] + weight ? f[i] : f[i-cost] + weight;
}
int main() {
scanf("%d%d",&n,&m);
forn(i,n) scanf("%d%d",&c[i],&w[i]);
forn(i,n) ZeroOnePack(w[i],c[i]);
printf("%d\n",f[m]);
return 0;
}