n, k = map(int, input().split()) pd = [list(map(int, input().split())) for _ in range(n)] pd.sort() dp = [[0] * 2 for _ in range(k + 1)] for p, d in pd: for j in range(k, p - 1, -1): dp[j][0] = max(dp[j][0], dp[j][1] + d) dp[j][1] = max(dp[j][1], dp[j - p][0] + d) for j in range(p - 1, -1, -1): dp[j][0] = max(dp[j][0], dp[j][1] + d) ans = max(v for _, v in dp) print(ans)