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

C=[0]*-~W

for _ in[0]*N:

 v,w=list(map(int,input().split()))

 for i in range(W,w-1,-1):

  t=v+C[i-w]

  if t>C[i]:C[i]=t

print((C[W]))

import sys

def s():

 W=int(input().split()[1])

 C=[0]*-~W

 for e in sys.stdin:

  v,w=list(map(int,e.split()))

  for i in range(W,w-1,-1):

   t=v+C[i-w]

   if t>C[i]:C[i]=t

 print((C[W]))

if'__main__'==__name__:s()

N, W = list(map(int, input().split()))
C = [0] * -~W
for _ in [0] * N:
    v, w = list(map(int, input().split()))
    for i in range(W, w - 1, -1):
        t = v + C[i - w]
        if t > C[i]:
            C[i] = t
print((C[W]))

import sys


def s():
    W = int(input().split()[1])
    C = [0] * -~W
    for e in sys.stdin:
        v, w = list(map(int, e.split()))
        for i in range(W, w - 1, -1):
            t = v + C[i - w]
            if t > C[i]:
                C[i] = t
    print((C[W]))


if "__main__" == __name__:
    s()

-N, W = list(map(int, input().split())) -C = [0] * -~W -for _ in [0] * N: -    v, w = list(map(int, input().split())) -    for i in range(W, w - 1, -1): -        t = v + C[i - w] -        if t > C[i]: -            C[i] = t -print((C[W])) +import sys + + +def s(): +    W = int(input().split()[1]) +    C = [0] * -~W +    for e in sys.stdin: +        v, w = list(map(int, e.split())) +        for i in range(W, w - 1, -1): +            t = v + C[i - w] +            if t > C[i]: +                C[i] = t +    print((C[W])) + + +if "__main__" == __name__: +    s()