n, _w = gets.split.map(&:to_i)
 
ans = 0
dp = Hash.new(_w + 1)
dp[0] = 0
n.times do
  prev = dp.dup
  w, v = gets.split.map(&:to_i)
  prev.each do |pv, pw|
    nw = pw + w
    nv = pv + v
    if nw <= _w && dp[nv] > nw  
      dp[nv] = nw
      ans = nv > ans ? nv : ans
    end
  end
end

puts ans
