n, m = map(int,input().split())
v = []
w = []
for _ in range(n):
a,b = map(int,input().split())
v.append(a)
w.append(b)
f = [[0 for _ in range(m+1)] for _ in range(n)]
for i in range(n):
for j in range(m+1): # ! 注意是m+1
t = int(j/v[i])
for k in range(t+1):
f[i][j] = max(f[i][j], f[i-1][j-k*v[i]] + k*w[i])
print(f[n-1][m])