import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{//try{
	auto tokens = split(my_readln());
	auto N = to!ulong(tokens[0]);
	auto W = to!ulong(tokens[1]);

	long[] w, v;
	foreach (i; 0..N)
	{
		auto tokens2 = split(my_readln());
		{
			w ~= to!long(tokens2[0]);
			v ~= to!long(tokens2[1]);
		}
	}

	long[][] dp;
	dp.length = 100100;
	foreach (ref e; dp) e.length = 110;

	foreach (i; 0..N)
	{
		foreach (j; 0..W+1)
		{
			if (j >= w[i]) dp[j][i+1] = max(dp[j-w[i]][i] + v[i], dp[j][i]);
			else dp[j][i+1] = dp[j][i];
		}
	}

	writeln(dp[W][N]);
	stdout.flush();
	/*}catch (Throwable e)
	{
	writeln(e.toString());
	}
	readln();*/
}