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

dp = [0]*(W + 1)



def solve_knapsack(capacity):

    # basic checks

 

    

    # populate the capacity = 0 columns, with '0' capacity we have '0' profit



    for i in range(0, N):

        weights,profits = list(map(int,input().split()))

        for c in range(capacity, weights-1, -1):

            tmp = profits + dp[c - weights]

            if tmp > dp[c]: dp[c] = tmp

 

    # maximum profit will be at the bottom-right corner.

    return dp[capacity]

  

def main():

 

    res = solve_knapsack(W)

 

    print(res)

if __name__ == "__main__":

	main()
N,W=list(map(int,input().split()))



def solve_knapsack(capacity):

    # basic checks

 

    

    # populate the capacity = 0 columns, with '0' capacity we have '0' profit

    dp = [0]*(W + 1)

    weights, profits = [0]*(N+1), [0]*(N+1)

    



    for i in range(0, N):

        weights,profits = list(map(int,input().split()))

        for c in range(capacity, weights-1, -1):

            tmp = profits + dp[c - weights]

            if tmp > dp[c]: dp[c] = tmp

 

    # maximum profit will be at the bottom-right corner.

    return dp[capacity]

  

def main():

    

 

    res = solve_knapsack(W)

 

    print(res)

if __name__ == "__main__":

	main()
N, W = list(map(int, input().split()))
dp = [0] * (W + 1)


def solve_knapsack(capacity):
    # basic checks
    # populate the capacity = 0 columns, with '0' capacity we have '0' profit
    for i in range(0, N):
        weights, profits = list(map(int, input().split()))
        for c in range(capacity, weights - 1, -1):
            tmp = profits + dp[c - weights]
            if tmp > dp[c]:
                dp[c] = tmp
    # maximum profit will be at the bottom-right corner.
    return dp[capacity]


def main():
    res = solve_knapsack(W)
    print(res)


if __name__ == "__main__":
    main()

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


def solve_knapsack(capacity):
    # basic checks
    # populate the capacity = 0 columns, with '0' capacity we have '0' profit
    dp = [0] * (W + 1)
    weights, profits = [0] * (N + 1), [0] * (N + 1)
    for i in range(0, N):
        weights, profits = list(map(int, input().split()))
        for c in range(capacity, weights - 1, -1):
            tmp = profits + dp[c - weights]
            if tmp > dp[c]:
                dp[c] = tmp
    # maximum profit will be at the bottom-right corner.
    return dp[capacity]


def main():
    res = solve_knapsack(W)
    print(res)


if __name__ == "__main__":
    main()

-dp = [0] * (W + 1) +    dp = [0] * (W + 1) +    weights, profits = [0] * (N + 1), [0] * (N + 1)