#include<cstdio>
#include<iostream>
#define ll long long
using namespace std;

ll dp[100000 +10], w[100000 +10];
ll v[100000 +10];
int main()
{
	int n,m; cin>>n>>m;
	int i,j;
	for(i=1;i<=n;i++) cin>>w[i]>>v[i];
	
	for(i=1;i<=n;i++)
	{
		for(j=m;j>=w[i];j--)
		{
			dp[j] = max(dp[j] , dp[j-w[i]] + v[i]);
		}
	}
	printf("%lld\n",dp[m]);
	return 0;
}