#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define max(a,b) a>b?a:b
int main() {
	int w[200], v[200], dp[201][201] = {};
	int i, j, n, W;
	fscanf(stdin, "%d%d", &n, &W);
	for (i = 1; i <= n; i++) fscanf(stdin, "%d%d", v + i, w + i);
	for (i = 1; i <= n; i++)
		for (j = 0; j <= W; j++) {
			if (w[i] > j) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
		}
	P(d, dp[n][W]);
	return 0;
}