local ffi=require"ffi"
ffi.cdef[[
int scanf(const char*,...);
int printf(const char*,...);
]]
local C=ffi.C

local function max(a,b)return a<b and b or a end

N=io.read"*n"
W=io.read"*n"
w,v={},{}for i=1,N do
w[i]=io.read"*n"
v[i]=io.read"*n"end

dp=ffi.new("int64_t[100][100000]")
for i=0,W do dp[0][i]=0 end

for i=1,N do
dp[i]={}
for j=0,W do
if(j<w[i])then dp[i][j]=dp[i-1][j]
else dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j])end
end
end
C.printf("%ld\n",dp[N][W])