N, W = gets.split.map &:to_i
items = N.times.map { gets.split.map(&:to_i) }
items.sort { |a, b| b[1] <=> a[1] }

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

max = 0
dp.each do |(w, v)|
  max = v if w <= W and max < v
end

p max