import java.util.*

fun main(args: Array<String>) {
	val (n, w) = readLine()!!.split(" ").map { it.toInt() }
	val values_list = Array<MutableList<Int>>(4) { mutableListOf(Int.MAX_VALUE) }
	var base = 0
	for (i in 0..(n - 1)) {
		val (a, b) = readLine()!!.split(" ").map { it.toInt() }
		if (i == 0) {
			base = a
		}
		values_list[a - base].add(b)
	}
	val values = Array<IntArray>(4) { values_list[it].toIntArray() }
	for (arr in values) {
		arr.sort()
		arr.reverse()
		arr[0] = 0
		for (i in 1..(arr.size - 1)) {
			arr[i] += arr[i - 1]
		}
	}
	var ans = 0
	for (i in 0..Math.min(w / base, values[0].size - 1)) {
		val rest0 = w - i * base
		var sum0 = values[0][i]
		for (j in 0..Math.min(rest0 / (base + 1), values[1].size - 1)) {
			val rest1 = rest0 - j * (base + 1)
			val sum1 = sum0 + values[1][j]
			for (k in 0..Math.min(rest1 / (base + 2), values[2].size - 1)) {
				val rest2 = rest1 - k * (base + 2)
				val sum2 = sum1 + values[2][k]
				val sum = sum2 + values[3][Math.min(rest2 / (base + 3), values[3].size - 1)]
				ans = Math.max(sum, ans)
			}
		}
	}
	println(ans)
}
