// AOJ DPL_1_B 0-1 Knapsack Problem
// 2018.5.4 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
while (c < '0') c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int dp[2][10002];

int knapsack01(int N, int W, int *v, int *w)
{
	int i, j, nw, nv, ans;
	int k1, k2;

	memset(dp, -1, sizeof(dp)); dp[0][0] = 0;
	for (k1 = 0, k2 = 1, i = 0; i < N; i++, k1 = k2, k2 = !k2) {
		memcpy(dp[k2], dp[k1], sizeof(dp[k2]));
		for (j = 0; j < W; j++) if (dp[k1][j] >= 0) {
			if ((nw = j + w[i]) > W) break;
			nv = dp[k1][j]+v[i];
			if (nv > dp[k2][nw]) dp[k2][nw] = nv;
		}
	}
	ans = 0; for (i = 1; i <= W; i++) if (dp[k1][i] > ans) ans = dp[k1][i]; 
	return ans;
}

int val[102], weight[102];

int main()
{
	int n, N, W, i;

	n = in(), W = in();
	N = 0; for (i = 0; i < n; i++) {
		val[N] = in(), weight[N] = in();
		if (weight[N] <= W) N++;
	}
	printf("%d\n", knapsack01(N, W, val, weight));
	return 0;
}
