# import sys

# sys.setrecursionlimit(10**5)

# from collections import defaultdict

import sys

readline = sys.stdin.buffer.readline

geta = lambda fn: list(map(fn, readline().split()))

gete = lambda fn: fn(readline())





N, W = geta(int)

cur = [0] * (W+1) 



for i in range(N):

    w, v = geta(int)

    update = cur[:]

    for j in range(w,W+1):

        tmp = cur[j-w] + v

        if tmp > cur[j]: update[j] = tmp

    

    cur = update



print((cur[W]))

# import sys

# sys.setrecursionlimit(10**5)

# from collections import defaultdict

import sys

readline = sys.stdin.buffer.readline

geta = lambda fn: list(map(fn, readline().split()))

gete = lambda fn: fn(readline())



def main():

    N, W = geta(int)

    cur = [0] * (W+1) 



    for i in range(N):

        w, v = geta(int)

        update = cur[:]

        for j in range(w,W+1):

            tmp = cur[j-w] + v

            if tmp > cur[j]: update[j] = tmp

        

        cur = update



    print((cur[W]))



if __name__ == "__main__":

    main()
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
import sys

readline = sys.stdin.buffer.readline
geta = lambda fn: list(map(fn, readline().split()))
gete = lambda fn: fn(readline())
N, W = geta(int)
cur = [0] * (W + 1)
for i in range(N):
    w, v = geta(int)
    update = cur[:]
    for j in range(w, W + 1):
        tmp = cur[j - w] + v
        if tmp > cur[j]:
            update[j] = tmp
    cur = update
print((cur[W]))

# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
import sys

readline = sys.stdin.buffer.readline
geta = lambda fn: list(map(fn, readline().split()))
gete = lambda fn: fn(readline())


def main():
    N, W = geta(int)
    cur = [0] * (W + 1)
    for i in range(N):
        w, v = geta(int)
        update = cur[:]
        for j in range(w, W + 1):
            tmp = cur[j - w] + v
            if tmp > cur[j]:
                update[j] = tmp
        cur = update
    print((cur[W]))


if __name__ == "__main__":
    main()

-N, W = geta(int) -cur = [0] * (W + 1) -for i in range(N): -    w, v = geta(int) -    update = cur[:] -    for j in range(w, W + 1): -        tmp = cur[j - w] + v -        if tmp > cur[j]: -            update[j] = tmp -    cur = update -print((cur[W])) + + +def main(): +    N, W = geta(int) +    cur = [0] * (W + 1) +    for i in range(N): +        w, v = geta(int) +        update = cur[:] +        for j in range(w, W + 1): +            tmp = cur[j - w] + v +            if tmp > cur[j]: +                update[j] = tmp +        cur = update +    print((cur[W])) + + +if __name__ == "__main__": +    main()