n,m=map(int,input().split())
A=[0]*(m+1)
S=0
for k in range(n):
i,j=map(int,input().split())
S+=i
for p in range(m,i-1,-1):
A[p]=max(A[p],j+A[p-i])
print(A[m])
#Cấm copy ai giống báo admin
bixtPW1hcChpbnQsaW5wdXQoKS5zcGxpdCgpKQpBPVswXSoobSsxKQpTPTAKZm9yIGsgaW4gcmFuZ2Uobik6CiAgICBpLGo9bWFwKGludCxpbnB1dCgpLnNwbGl0KCkpCiAgICBTKz1pCiAgICBmb3IgcCBpbiByYW5nZShtLGktMSwtMSk6CiAgICAgICAgQVtwXT1tYXgoQVtwXSxqK0FbcC1pXSkKcHJpbnQoQVttXSkKI0PhuqVtIGNvcHkgYWkgZ2nhu5FuZyBiw6FvIGFkbWlu