N, W = gets.split.map &:to_i
items = N.times.map { gets.split.map(&:to_i) }

dp = [nil] * 1001000
dp[0] = [0, 0]
len = 1
items.each do |item|
  len.times do |i|
    w, v = dp[i]
    w += item[0]
    v += item[1]
    if w <= W
      dp[len] = [w, v]
      len += 1
    end
  end
  #dp += dp.map { |(w, v)| [w + item[0], v + item[1]] }
end

max = 0
len.times do |i|
  w, v = dp[i]
  max = v if w <= W and max < v
end

p max