import sys



def solve():

    file_input = sys.stdin

    N, W = list(map(int, file_input.readline().split()))

    C = [0] * (W + 1)

    for line in file_input:

        item_v, item_w = list(map(int, line.split()))

        for i, vals in enumerate(zip(C[item_w:], C)):

            C[i] = max(vals[0] + item_v, vals[1])

    print((C[0]))



solve()
import sys



def solve():

    file_input = sys.stdin

    N, W = list(map(int, file_input.readline().split()))

    C = [0] * (W + 1)

    for line in file_input:

        item_v, item_w = list(map(int, line.split()))

        for i, vals in enumerate(zip(C[item_w:], C)):

            v1, v2 = vals

            C[i] = max(v1 + item_v, v2)

    print((C[0]))



solve()
import sys


def solve():
    file_input = sys.stdin
    N, W = list(map(int, file_input.readline().split()))
    C = [0] * (W + 1)
    for line in file_input:
        item_v, item_w = list(map(int, line.split()))
        for i, vals in enumerate(zip(C[item_w:], C)):
            C[i] = max(vals[0] + item_v, vals[1])
    print((C[0]))


solve()

import sys


def solve():
    file_input = sys.stdin
    N, W = list(map(int, file_input.readline().split()))
    C = [0] * (W + 1)
    for line in file_input:
        item_v, item_w = list(map(int, line.split()))
        for i, vals in enumerate(zip(C[item_w:], C)):
            v1, v2 = vals
            C[i] = max(v1 + item_v, v2)
    print((C[0]))


solve()

-            C[i] = max(vals[0] + item_v, vals[1]) +            v1, v2 = vals +            C[i] = max(v1 + item_v, v2)