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

things = []

things.append([0,0])

things += [list(map(int, input().split())) for _ in range(n)]



dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]



def do_dp():

  for i,thing in enumerate(things):

    dp_1 = dp[i-1]

    for j in range(1, w + 1):      

      dp[i][j] = dp_1[j-thing[0]] + thing[1]  if (j - thing[0]) >= 0 else dp_1[j]

      dp[i][j] = max(dp[i][j], dp_1[j])



do_dp()

print((dp[n][w]))

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



dp = [0]*(w+1)



for _ in range(n):

  wei, v = list(map(int, input().split()))

  dp_1 = dp[:]

  for j in range(w + 1):

    if j - wei >= 0:

      dp[j] = dp_1[j-wei] + v if (dp_1[j-wei] + v) > dp_1[j] else dp[j]

  

print((dp[w]))

n, w = list(map(int, input().split()))
things = []
things.append([0, 0])
things += [list(map(int, input().split())) for _ in range(n)]
dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]


def do_dp():
    for i, thing in enumerate(things):
        dp_1 = dp[i - 1]
        for j in range(1, w + 1):
            dp[i][j] = dp_1[j - thing[0]] + thing[1] if (j - thing[0]) >= 0 else dp_1[j]
            dp[i][j] = max(dp[i][j], dp_1[j])


do_dp()
print((dp[n][w]))

n, w = list(map(int, input().split()))
dp = [0] * (w + 1)
for _ in range(n):
    wei, v = list(map(int, input().split()))
    dp_1 = dp[:]
    for j in range(w + 1):
        if j - wei >= 0:
            dp[j] = dp_1[j - wei] + v if (dp_1[j - wei] + v) > dp_1[j] else dp[j]
print((dp[w]))

-things = [] -things.append([0, 0]) -things += [list(map(int, input().split())) for _ in range(n)] -dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)] - - -def do_dp(): -    for i, thing in enumerate(things): -        dp_1 = dp[i - 1] -        for j in range(1, w + 1): -            dp[i][j] = dp_1[j - thing[0]] + thing[1] if (j - thing[0]) >= 0 else dp_1[j] -            dp[i][j] = max(dp[i][j], dp_1[j]) - - -do_dp() -print((dp[n][w])) +dp = [0] * (w + 1) +for _ in range(n): +    wei, v = list(map(int, input().split())) +    dp_1 = dp[:] +    for j in range(w + 1): +        if j - wei >= 0: +            dp[j] = dp_1[j - wei] + v if (dp_1[j - wei] + v) > dp_1[j] else dp[j] +print((dp[w]))