from collections import deque def main(): N, M = map(int, input().split()) hand = [] for _ in range(N): C, D = map(int, input().split()) hand.append((C, D)) # Sort the hand by the first value in descending order hand.sort(reverse=True, key=lambda x: (x[0], x[1])) dp = [0] * (M + 1) dp[M] = 0 for C, D in hand: dp_next = [0] * (M + 1) for i in range(C, M + 1): if dp[i] + D > dp_next[(i - C) // 2]: dp_next[(i - C) // 2] = dp[i] + D for i in range(0, M + 1): dp_next[i] = max(dp_next[i], dp[i]) dp = dp_next ans = max(dp) print(ans) if __name__ == "__main__": main()