def main
  n, w = gets.split(" ").map(&:to_i)
  arr = Array.new(w + 1, nil)
  arr[0] = 0
  goods = []
  n.times do
    goods << gets.split(" ").map(&:to_i)
  end
  goods.each{|good|
    -1.downto(-w - 1){|weight|
      if arr[weight] and (weight + good[1]) < 0 and (!arr[weight + good[1]] or arr[weight + good[1]] < (arr[weight] + good[0]))
        arr[weight + good[1]] = arr[weight] + good[0]
      end
    }
  }
  puts arr.select{|i|i}.max
end
main