# dpD - Knapsack 1

import sys

input = sys.stdin.readline



def main():

    n, w = tuple(map(int, input().rstrip().split()))

    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n))

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

    for i in range(n):

        for j in range(w + 1):

            if j < A[i][0]:

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

            else:

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

    print((max(dp[-1])))





if __name__ == "__main__":

    main()
# dpD

import sys

input = sys.stdin.readline



def main():

    N, W = tuple(map(int, input().rstrip().split()))

    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(N))

    dp = [0] * (W + 1)

    for i in range(N):

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

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

    print((dp[-1]))





if __name__ == "__main__":

    main()
# dpD - Knapsack 1
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

# dpD
import sys

input = sys.stdin.readline


def main():
    N, W = tuple(map(int, input().rstrip().split()))
    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(N))
    dp = [0] * (W + 1)
    for i in range(N):
        for j in range(W, A[i][0] - 1, -1):
            dp[j] = max(dp[j], dp[j - A[i][0]] + A[i][1])
    print((dp[-1]))


if __name__ == "__main__":
    main()

-# dpD - Knapsack 1 +# dpD -    n, w = tuple(map(int, input().rstrip().split())) -    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(n)) -    dp = [[0] * (w + 1) for i in range(n)] -    for i in range(n): -        for j in range(w + 1): -            if j < A[i][0]: -                dp[i][j] = dp[i - 1][j] -            else: -                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - A[i][0]] + A[i][1]) -    print((max(dp[-1]))) +    N, W = tuple(map(int, input().rstrip().split())) +    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(N)) +    dp = [0] * (W + 1) +    for i in range(N): +        for j in range(W, A[i][0] - 1, -1): +            dp[j] = max(dp[j], dp[j - A[i][0]] + A[i][1]) +    print((dp[-1]))