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

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

for i in range(1,n+1):

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

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

        if j-w<0:

            dp[i][j]=dp[i-1][j]

        else:

            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v)

print((max(dp[n])))
import sys

input = sys.stdin.readline

import numpy as np



def main():

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

    dp = np.zeros(W + 1, dtype = np.int64)

    for i in range(n):

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

        dp[w:]=np.maximum(dp[w:],dp[:-w]+v)

    print((max(dp)))



if __name__ == '__main__':

    main()
n, W = list(map(int, input().split()))
dp = [[0] * (W + 1) for _ in range(n + 1)]
for i in range(1, n + 1):
    w, v = list(map(int, input().split()))
    for j in range(1, W + 1):
        if j - w < 0:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v)
print((max(dp[n])))

import sys

input = sys.stdin.readline
import numpy as np


def main():
    n, W = list(map(int, input().split()))
    dp = np.zeros(W + 1, dtype=np.int64)
    for i in range(n):
        w, v = list(map(int, input().split()))
        dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
    print((max(dp)))


if __name__ == "__main__":
    main()

-n, W = list(map(int, input().split())) -dp = [[0] * (W + 1) for _ in range(n + 1)] -for i in range(1, n + 1): -    w, v = list(map(int, input().split())) -    for j in range(1, W + 1): -        if j - w < 0: -            dp[i][j] = dp[i - 1][j] -        else: -            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v) -print((max(dp[n]))) +import sys + +input = sys.stdin.readline +import numpy as np + + +def main(): +    n, W = list(map(int, input().split())) +    dp = np.zeros(W + 1, dtype=np.int64) +    for i in range(n): +        w, v = list(map(int, input().split())) +        dp[w:] = np.maximum(dp[w:], dp[:-w] + v) +    print((max(dp))) + + +if __name__ == "__main__": +    main()