object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, w = sc.nextInt()
  val wv = List.fill(n)((sc.nextLong(), sc.nextInt()))
  val x = wv.head._1
  val w0 = wv.filter(_._1 == x).map(_._2).sorted.reverse.scanLeft(0)(_ + _)
  val w1 = wv.filter(_._1 == x+1).map(_._2).sorted.reverse.scanLeft(0)(_ + _)
  val w2 = wv.filter(_._1 == x+2).map(_._2).sorted.reverse.scanLeft(0)(_ + _)
  val w3 = wv.filter(_._1 == x+3).map(_._2).sorted.reverse.scanLeft(0)(_ + _).toArray

  var ans = 0
  for {
    (v0, i0) <- w0.zipWithIndex
    (v1, i1) <- w1.zipWithIndex
    (v2, i2) <- w2.zipWithIndex
  } {
    val rest = w - (i0 * x + i1 * (x+1) + i2 * (x+2))
    if (rest >= 0) {
      val i3 = (rest / (x+3)).min(w3.length-1).toInt
      ans = ans.max(v0 + v1 + v2 + w3(i3))
    }
  }
  println(ans)
}
