def resolve():

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

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

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



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

        for j in range(w + 1):

            tmp = dp[i - 1][j - goods[i - 1][0]] + goods[i - 1][1] if j >= goods[i - 1][0] else 0

            dp[i][j] = max(dp[i - 1][j], tmp)



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

    

resolve()
import numpy as np

def resolve():

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

    goods = np.array([list(map(int, input().split())) for _ in range(n)])

    dp = np.zeros([n + 1, w + 1], dtype=int)



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

        tmp = np.zeros(w + 1, dtype=int)

        tmp[goods[i - 1][0]:] = dp[i - 1][:-goods[i - 1][0]] + goods[i - 1][1]

        dp[i] = np.maximum(dp[i - 1], tmp)



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

    

resolve()
def resolve():
    n, w = list(map(int, input().split()))
    goods = [list(map(int, input().split())) for _ in range(n)]
    dp = [[0] * (w + 1) for _ in range(n + 1)]
    for i in range(1, n + 1):
        for j in range(w + 1):
            tmp = (
                dp[i - 1][j - goods[i - 1][0]] + goods[i - 1][1]
                if j >= goods[i - 1][0]
                else 0
            )
            dp[i][j] = max(dp[i - 1][j], tmp)
    print((dp[n][w]))


resolve()

import numpy as np


def resolve():
    n, w = list(map(int, input().split()))
    goods = np.array([list(map(int, input().split())) for _ in range(n)])
    dp = np.zeros([n + 1, w + 1], dtype=int)
    for i in range(1, n + 1):
        tmp = np.zeros(w + 1, dtype=int)
        tmp[goods[i - 1][0] :] = dp[i - 1][: -goods[i - 1][0]] + goods[i - 1][1]
        dp[i] = np.maximum(dp[i - 1], tmp)
    print((dp[n][w]))


resolve()

+import numpy as np + + -    goods = [list(map(int, input().split())) for _ in range(n)] -    dp = [[0] * (w + 1) for _ in range(n + 1)] +    goods = np.array([list(map(int, input().split())) for _ in range(n)]) +    dp = np.zeros([n + 1, w + 1], dtype=int) -        for j in range(w + 1): -            tmp = ( -                dp[i - 1][j - goods[i - 1][0]] + goods[i - 1][1] -                if j >= goods[i - 1][0] -                else 0 -            ) -            dp[i][j] = max(dp[i - 1][j], tmp) +        tmp = np.zeros(w + 1, dtype=int) +        tmp[goods[i - 1][0] :] = dp[i - 1][: -goods[i - 1][0]] + goods[i - 1][1] +        dp[i] = np.maximum(dp[i - 1], tmp)