// AOJ DPL_1_C 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();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX_N 102
#define MAX_W 10002

int N, M;
int dp[MAX_W];

// v[]: value, w[]: weight
int knapsack(int N, int W, int *v, int *w)
{
	int i, j;
	
	memset(dp, 0, W<<2);
	for (i = 0; i < N; i++) {
		for (j = w[i]; j <= W; j++) {
			int d = j - w[i], x = dp[d] + v[i];
			if (x > dp[j]) dp[j] = x;
		}
	}
	return dp[W];
}

int val[MAX_N], weight[MAX_N];

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

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

