import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def main(): n, k = map(int, input().split()) PD = [] for i in range(n): p, d = map(int, input().split()) PD.append((p,d)) PD.sort(key=lambda x: -x[0]) INF = 10**18 dp = [[-INF]*2 for i in range(k+1)] dp[0][0] = 0 for p, d in PD: nx = [[-INF]*2 for i in range(k+1)] for i in range(k+1): for j in range(2): nx[i][j] = max(nx[i][j], dp[i][j]) for i in range(k+1): for j in range(2): if dp[i][j] == -INF: continue if j == 0: if i+p <= k: nx[i+p][1] = max(nx[i+p][1], dp[i][j]+d) else: nx[i][0] = max(nx[i][0], dp[i][j]+d) dp = nx #print(dp) ans = -INF for i in range(k+1): for j in range(2): ans = max(ans, dp[i][j]) print(ans) if __name__ == '__main__': main()