class Object:
def __init__(self, w, c):
self.w = w
self.c = c
def dynamic_programming_in_action( arr, N, Gmax ):
Profit = [[ 0 for j in range(Gmax+1 ) ] for i in range(0, N +1 )]
for i in range( 1, N + 1 ):
for j in range(1, Gmax+1):
if arr[i].w <= j:
Profit[i][j] = max(arr[i].c + Profit[i-1][j-arr[i].w], Profit[i-1][j])
else:
Profit[i][j] = Profit[i-1][j]
print(Profit[N][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()
Y2xhc3MgT2JqZWN0OgoKICAgIGRlZiBfX2luaXRfXyhzZWxmLCB3LCBjKToKCiAgICAgICAgc2VsZi53ID0gdwoKICAgICAgICBzZWxmLmMgPSBjCgpkZWYgZHluYW1pY19wcm9ncmFtbWluZ19pbl9hY3Rpb24oIGFyciwgTiwgR21heCApOgoKICAgIFByb2ZpdCA9IFtbIDAgZm9yIGogaW4gcmFuZ2UoR21heCsxICkgXSBmb3IgaSBpbiByYW5nZSgwLCBOICsxICldCgogICAgZm9yIGkgaW4gcmFuZ2UoIDEsIE4gKyAxICk6CgogICAgICAgIGZvciBqIGluIHJhbmdlKDEsIEdtYXgrMSk6CgogICAgICAgICAgICBpZiBhcnJbaV0udyA8PSBqOgoKICAgICAgICAgICAgICAgUHJvZml0W2ldW2pdID0gbWF4KGFycltpXS5jICsgUHJvZml0W2ktMV1bai1hcnJbaV0ud10sIFByb2ZpdFtpLTFdW2pdKQoKICAgICAgICAgICAgZWxzZToKCiAgICAgICAgICAgICAgIFByb2ZpdFtpXVtqXSA9IFByb2ZpdFtpLTFdW2pdCgogICAgcHJpbnQoUHJvZml0W05dW0dtYXhdKQoKZGVmIGZuKCk6CgogICAgICAgIGNvbnRlbnQgPSBbeC5zdHJpcCgpIGZvciB4IGluIGlucHV0KCkuc3BsaXQoKV0KCiAgICAgICAgbnVtX29mX29iamVjdHMgPSBpbnQoY29udGVudFswXSkKCiAgICAgICAgR21heCA9IGludChjb250ZW50WzFdKQoKICAgICAgICBhcnIgPSBbMF0KCiAgICAgICAgZm9yIGkgaW4gcmFuZ2UoMSxudW1fb2Zfb2JqZWN0cyArIDEpOgoKICAgICAgICAgICAgICBjb250ZW50ID0gW3guc3RyaXAoKSBmb3IgeCBpbiBpbnB1dCgpLnNwbGl0KCldCgogICAgICAgICAgICAgIHcgPSBpbnQoY29udGVudFsgMCBdKQoKICAgICAgICAgICAgICBjID0gaW50KGNvbnRlbnRbIDEgXSkKCiAgICAgICAgICAgICAgYXJyLmFwcGVuZChPYmplY3QoIHcsIGMgKSkKCiAgICAgICAgZHluYW1pY19wcm9ncmFtbWluZ19pbl9hY3Rpb24oIGFyciwgbnVtX29mX29iamVjdHMsIEdtYXggKQoKZm4oKQ==