N=1005
#f[i][j]:选取i个物品,体积<=j
#划分:选第j个k次 f[i-1][j-k*v[i]]+k*w[i]
#不选 f[i-1][j]
#直接使用k遍历,时间复杂度过不去,优化一下即可过去
f=[[0 for i in range(N)]for j in range(N)]
a=[0 for i in range(N)]
b=[0 for i in range(N)]
n,v=map(int,input().split())
for i in range(1,n+1):
a[i],b[i]=map(int,input().split())
for i in range(1,n+1):
for j in range(0,v+1):
f[i][j] = f[i-1][j]
if(j-a[i]>=0):
f[i][j]=max(f[i][j],f[i][j-a[i]]+b[i])
print(f[n][v])