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

