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)):

            v1, v2 = vals

            v1 += item_v

            if v1 > v2:

                C[i] = v1

    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)):
            v1, v2 = vals
            v1 += item_v
            if v1 > v2:
                C[i] = v1
    print((C[0]))


solve()

-            C[i] = max(v1 + item_v, v2) +            v1 += item_v +            if v1 > v2: +                C[i] = v1