WV = $<.read.split.map(&:to_i).each_slice(2).to_a
N,W = WV.shift
WV.sort_by! {|w,v| w>W ? 1<<60 : (v<<30)+w}
I = [0]
tv=tw = 0
i = WV.each_with_index {|(w,v),i|
  break 0...i  if w > W
  I << I[-1]=[v,i]   if I[-1][0] < v
  tv+=v; tw+=w
}.size
I[-1] = [1<<60,i]
A = Array.new(tv+1, [tw, -1])
A[0] = [0,0]
l = tw > W ? 0 : tv
l.upto(tv-1) {|n|
  c,b = A[n]
  l = n if c <= W
  next  if c >= W
  0.upto(I.size-2) {|i|
    j = I[i+1][1]
    next  if b[j-1] > 0
    v,i = I[i]
    next  if A[v+n][0] <= c + WV[i][0]
    if j > i+9
      i = (i...j).bsearch {|x| b[x] == 0}
    else
      i += 1  while b[i] > 0
    end
    w = c + WV[i][0]
    x = b | b+(1<<i)
    A[v+n] = [w,x]  if A[v+n][0] > w
  }
}
p l