#include<stdio.h>
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define LARGE 101

int main(){
	int i,j,N,W;
	int v[LARGE];
	int w[LARGE];
	int dp[LARGE][LARGE];

	scanf("%d %d",&N,&W);
	
	for(i=1;i<=N;i++){
		scanf("%d %d",&v[i],&w[i]);
	}
	
	for(i=0;i<=N;i++){
		for(j=0;j<=W;j++)dp[i][j]=-1;
	}
	
	for(i=0;i<=N;i++)dp[i][0]=0;
	
	for(i=1;i<=N;i++){
		for(j=0;j<=W;j++){
			if(dp[i-1][j]!=-1){
				dp[i][j]=MAX(dp[i-1][j],dp[i][j]);
				if(j+w[i]<=W)dp[i][j+w[i]]=MAX(dp[i][j+w[i]],dp[i-1][j]+v[i]);
			}
		}
	}
	int max=-1;
	for(i=0;i<=W;i++){
		if(dp[N][i]>max)max=dp[N][i];
	}
	printf("%d\n",max);
	
	return 0;
}
