# conver the following C++ code into pypy3 #https://yukicoder.me/submissions/1041891 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: for i in range(C, M + 1): dp[(i - C) // 2] = max(dp[(i - C) // 2], dp[i] + D) ans = max(dp) print(ans) if __name__ == "__main__": main()