//-----

var log = console.log;
if (typeof process != "undefined") {
	var input = "";
	process.stdin.resume();
	process.stdin.setEncoding('utf8');
	process.stdin.on('data', function (chunk) {
		input += chunk;
	});
	process.stdin.on('end', function () {
		var lines = input.split("\n");
		main(lines);
	});
}

//-----

function main(lines) {
	//??°????????????
	lines = lines.map(function (e) {
		if (e.split(" ").length >= 2) {
			return e.split(" ").map(function (f) {
				return Number(f);
			});
		} else {
			return Number(e);
		}
	});

	var tpl = lines.shift();
	var N = tpl.shift();
	var W = tpl.shift();
	var goods = lines;

	var i = N;
	var Wmax = goods.reduce(function (p, c) {
		if (p.length >= 1) return p[1] + c[1];
		return p + c[1];
	});
	var Vmax = goods.reduce(function (p, c) {
		if (p.length >= 1) return p[0] + c[0];
		return p + c[0];
	});
	//	log(Wmax,Vmax);

	log(V(N, W, Wmax, Vmax, goods));
}

function V(i, w, wmax, vmax, goods) {
	if (i - 1 >= 0 && w > 0) {
		if (w >= wmax) {
			//?????????????????????
			/*			log("sufficient");
   			log(i,w,vmax);*/
			return vmax;
		} else {
			var vi = goods[i - 1][0];
			var wi = goods[i - 1][1];
			/*			log("go to subprocess");
   			log(i,w);*/
			//????????????????????°????????????
			var ret = void 0;
			if (w - wi < 0) {
				ret = V(i - 1, w, wmax - wi, vmax - vi, goods);
			} else {
				ret = Math.max(V(i - 1, w - wi, wmax - wi, vmax - vi, goods) + vi, V(i - 1, w, wmax - wi, vmax - vi, goods));
			}
			/*			log("back from subprocess");
   			log(i,w,ret);*/
			return ret;
		}
	} else {
		/*		log("invalid");
  		log(i,w);*/
		//??????????????????????????????
		return 0;
	}
}