#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 1e4;
int f[maxn];
int w[maxn], val[maxn];
int solve(int n, int m){	
	memset(f, 0, sizeof f);	
	for(int i = 1;i <= n;i++){	
		for(int v = m; v > 0; v--){	
			if(v >= w[i])				
				f[v] = max(f[v],f[v-w[i]] + val[i]);	
		}	
	}
	return f[m];
}
int main(){	
	int n, m;	
	while(scanf(" %d %d", &n, &m) != EOF){		
		for(int i = 1;i <= n;i++) scanf(" %d %d", &w[i], &val[i]);
		solve(n, m);
		printf("%d\n", f[m]);
	}
	return 0;
}