local mmi, mma = math.min, math.max n, m = io.read("*n", "*n") t = {} for i = 1, m do t[i] = 0 end for rep = 1, n do s, a = io.read("*n", "*n") for i = m - s, 1, -1 do t[i + s] = mma(t[i + s], t[i] + a) end if s <= m then t[s] = mma(t[s], a) end end print(t[m])