# import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N,I = map(int,input().split()) sa = [tuple(map(int,input().split())) for _ in range(N)] dp = [[0]*(I+2) for _ in range(N)] s,a = sa[0] def f(x): return min(x,I+1) dp[0][f(s)] = a for i in range(N-1): s,a = sa[i+1] dp[i+1] = dp[i][:] for j in range(I+1): dp[i+1][f(j+s)] = max(dp[i+1][f(j+s)],dp[i][j]+a,dp[i][f(j+s)]) print(max(dp[-1][:I+1]))