class Object:
def __init__(self, w, c):
self.w = w
self.c = c
def dynamic_programming_in_action( arr, N, Gmax ):
Optime = [0 for j in range(Gmax+1)]
for i in range(1, N + 1):
for j in range(Gmax, 1, -1):
if j >= arr[i].w:
Optime[ j ] = max(Optime[ j ], arr[i].c + Optime[j-arr[i].w])
print( Optime[ Gmax ] )
def fn():
content = [x.strip() for x in input().split()]
num_of_objects = int(content[0])
Gmax = int(content[1])
arr = [0]
for i in range(1,num_of_objects + 1):
content = [x.strip() for x in input().split()]
w = int(content[ 0 ])
c = int(content[ 1 ])
arr.append(Object( w, c ))
dynamic_programming_in_action( arr, num_of_objects, Gmax )
fn()
Y2xhc3MgT2JqZWN0OgoKICAgIGRlZiBfX2luaXRfXyhzZWxmLCB3LCBjKToKCiAgICAgICAgc2VsZi53ID0gdwoKICAgICAgICBzZWxmLmMgPSBjCgpkZWYgZHluYW1pY19wcm9ncmFtbWluZ19pbl9hY3Rpb24oIGFyciwgTiwgR21heCApOgoKICAgIE9wdGltZSA9IFswIGZvciBqIGluIHJhbmdlKEdtYXgrMSldCgogICAgZm9yIGkgaW4gcmFuZ2UoMSwgTiArIDEpOgoKICAgICAgICBmb3IgaiBpbiByYW5nZShHbWF4LCAxLCAtMSk6CgogICAgICAgICAgICBpZiBqID49IGFycltpXS53OgoKICAgICAgICAgICAgICAgT3B0aW1lWyBqIF0gPSBtYXgoT3B0aW1lWyBqIF0sIGFycltpXS5jICsgT3B0aW1lW2otYXJyW2ldLnddKQoKICAgIHByaW50KCBPcHRpbWVbIEdtYXggXSApCgpkZWYgZm4oKToKICAgICAgICBjb250ZW50ID0gW3guc3RyaXAoKSBmb3IgeCBpbiBpbnB1dCgpLnNwbGl0KCldCgogICAgICAgIG51bV9vZl9vYmplY3RzID0gaW50KGNvbnRlbnRbMF0pCgogICAgICAgIEdtYXggPSBpbnQoY29udGVudFsxXSkKCiAgICAgICAgYXJyID0gWzBdCgogICAgICAgIGZvciBpIGluIHJhbmdlKDEsbnVtX29mX29iamVjdHMgKyAxKToKCiAgICAgICAgICAgICAgY29udGVudCA9IFt4LnN0cmlwKCkgZm9yIHggaW4gaW5wdXQoKS5zcGxpdCgpXQoKICAgICAgICAgICAgICB3ID0gaW50KGNvbnRlbnRbIDAgXSkKCiAgICAgICAgICAgICAgYyA9IGludChjb250ZW50WyAxIF0pCgogICAgICAgICAgICAgIGFyci5hcHBlbmQoT2JqZWN0KCB3LCBjICkpCgogICAgICAgIGR5bmFtaWNfcHJvZ3JhbW1pbmdfaW5fYWN0aW9uKCBhcnIsIG51bV9vZl9vYmplY3RzLCBHbWF4ICkKCmZuKCk=