#include<stdio.h>

#define MAXW 10050
#define MAXN 105 
int dp[MAXN][MAXW];
int max(int a, int b){return a>b?a:b;}

int main(){
	//i means:the first ith ele and j means: the capacity
	int N = 0,W=0;
	scanf("%d %d",&N,&W);
	
	int ele[N+1][2];
	for(int i = 1; i<=N;i++){
		scanf("%d %d",&ele[i][0],&ele[i][1]);//v,w	
	}
	//boundary case for dp
	for(int i = 0; i<=N; i++){
		dp[i][0] = 0;
	}
	for(int i = 0; i<=W; i++){
		dp[0][W] = 0;
	}
	for(int i = 1; i<=N; i++){
		for(int j = 1; j<=W; j++){
			if(j-ele[i][1]>=0){
				dp[i][j] = max(dp[i-1][j],dp[i-1][j-ele[i][1]]+ele[i][0]);
			}
			
		}
	}
	printf("%d",dp[N][W]);
	return 0;
}