n,w_max = gets.split.map(&:to_i)
weight,value = gets.split.map(&:to_i)

dp=[0] * w_max
for i in 0..weight-1
  dp[i]=0
end
for i in weight..w_max
  dp[i]=value
end

for i in 1...n
  pre_dp = dp.clone
  weight,value = gets.split.map(&:to_i)
  for j in 1..w_max
    if j-weight>=0
      dp[j] = pre_dp[j-weight] + value
      dp[j] = pre_dp[j] if dp[j]<pre_dp[j]
    end
  end
end
puts dp.last
