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