import sys

input = sys.stdin.readline

if __name__ == "__main__":
    n, w = map(int, input().split())
    jewelries = [tuple(map(int, input().split())) for _ in range(n)]

    dp = [0] * (w + 1)

    for weight, price in jewelries:
        for j in range(weight, w + 1):
            dp[j] = max(dp[j], dp[j - weight] + price)

    print(dp[w])