n,w=gets.split.map(&:to_i)
wv=n.times.map{gets.split.map(&:to_i)}
wv.unshift([])
d=Array.new(n+1){Array.new(w+1,0)}
1.upto(n){|i| 0.upto(w){|k| 
  d[i][k]=d[i-1][k]
  next if k<wv[i][0]
  d[i][k]=d[i-1][k-wv[i][0]]+wv[i][1] if d[i][k]<d[i-1][k-wv[i][0]]+wv[i][1]  
  }}
puts d[n][w]
