import sys

input = sys.stdin.readline

n,w = list(map(int,input().split()))

wv = [tuple(map(int,input().split())) for i in range(n)]



dp = [0]*(w+1)

for i in range(n):

    for j in range(w,wv[i][0]-1,-1):

        dp[j] = max(dp[j],dp[j-wv[i][0]]+wv[i][1])



print((max(dp)))
def MI(): return list(map(int, input().split()))

import sys

input = sys.stdin.readline

n,w = list(map(int,input().split()))

#wv = [tuple(map(int,input().split())) for i in range(n)]

W=[]

V=[]

for i in range(n):

  a,b=MI()

  W.append(a)

  V.append(b)

dp = [0]*(w+1)

for i in range(n):

    for j in range(w,W[i]-1,-1):

        dp[j] = max(dp[j],dp[j-W[i]]+V[i])

print((max(dp)))
import sys

input = sys.stdin.readline
n, w = list(map(int, input().split()))
wv = [tuple(map(int, input().split())) for i in range(n)]
dp = [0] * (w + 1)
for i in range(n):
    for j in range(w, wv[i][0] - 1, -1):
        dp[j] = max(dp[j], dp[j - wv[i][0]] + wv[i][1])
print((max(dp)))

def MI():
    return list(map(int, input().split()))


import sys

input = sys.stdin.readline
n, w = list(map(int, input().split()))
# wv = [tuple(map(int,input().split())) for i in range(n)]
W = []
V = []
for i in range(n):
    a, b = MI()
    W.append(a)
    V.append(b)
dp = [0] * (w + 1)
for i in range(n):
    for j in range(w, W[i] - 1, -1):
        dp[j] = max(dp[j], dp[j - W[i]] + V[i])
print((max(dp)))

+def MI(): +    return list(map(int, input().split())) + + -wv = [tuple(map(int, input().split())) for i in range(n)] +# wv = [tuple(map(int,input().split())) for i in range(n)] +W = [] +V = [] +for i in range(n): +    a, b = MI() +    W.append(a) +    V.append(b) -    for j in range(w, wv[i][0] - 1, -1): -        dp[j] = max(dp[j], dp[j - wv[i][0]] + wv[i][1]) +    for j in range(w, W[i] - 1, -1): +        dp[j] = max(dp[j], dp[j - W[i]] + V[i])