n, k = map(int, input().split()) info = [list(map(int, input().split())) for i in range(n)] info = sorted(info, reverse = True) dp = [[[0]*2 for _ in range(k+1)] for i in range(n+1)] for i in range(n): cost, val = info[i] for j in range(k+1): # i番目を無料としてもらう if dp[i][j][1] != 0: dp[i+1][j][0] = max(dp[i][j][1] + val, dp[i+1][j][0]) # i番目をお金を払ってもらう if j - cost >= 0: dp[i+1][j][1] = max(dp[i][j - cost][0] + val, dp[i+1][j][1]) # i番目をもらわない dp[i+1][j][0] = max(dp[i][j][0], dp[i+1][j][0]) dp[i+1][j][1] = max(dp[i][j][1], dp[i+1][j][1]) print(max(dp[n][k]))