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