fun main(args: Array<String>) {
    var (N, W) = pairIntLong()
    val WV = Array(N) { pairIntLong() }
    val WVs = Array(4) { mutableListOf<Long>() }
    val baseW = WV[0].first.toLong()
    WV.forEach { wv -> WVs[wv.first - WV[0].first].add(wv.second) }
    WVs.forEach {
        val w = it.sorted().toList()
        it.clear(); it.add(0L)
        for (n in w.indices.reversed()) it.add(w.subList(n, w.size).sum())
    }
    var ans = 0L
    for (n0 in (0 until WVs[0].size).reversed()) {
        val w0 = (baseW + 0) * n0
        for (n1 in (0 until WVs[1].size).reversed()) {
            val w1 = (baseW + 1) * n1
            for (n2 in (0 until WVs[2].size).reversed()) {
                val w2 = (baseW + 2) * n2
                for (n3 in (0 until WVs[3].size).reversed()) {
                    val w3 = (baseW + 3) * n3
                    if (w0 + w1 + w2 + w3 > W) continue
                    val v0 = WVs[0][n0]
                    val v1 = WVs[1][n1]
                    val v2 = WVs[2][n2]
                    val v3 = WVs[3][n3]
                    ans = Math.max(ans, v0 + v1 + v2 + v3)
                }
            }
        }
    }
    println(ans)
}
fun pairIntLong(offset: Pair<Int, Long> = Pair(0, 0L)) = listOfLong().let { Pair(it[0].toInt() + offset.first, it[1] + offset.second) }

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
