# https://yukicoder.me/problems/no/3808 import heapq MAX_INT = 10 ** 18 def main(): N, T = map(int, input().split()) ab = [] for _ in range(N): a, b = map(int, input().split()) ab.append((a, b)) base_a_map = {} for a, b in ab: if a not in base_a_map: base_a_map[a] = [MAX_INT, []] base_a_map[a][0] = min(base_a_map[a][0] ,b) base_a_map[a][1].append(b) base_a_array = [(key, tpl) for key, tpl in base_a_map.items()] base_a_array.sort(key=lambda x : x[1][0]) base_time = 0 queue = [] queue_time = 0 answer = 0 for spec_index in range(len(base_a_array)): b_array = base_a_array[spec_index][1][1] b_array.sort() base_time += b_array[0] while len(queue) > 0 and queue_time + base_time > T: b1 = heapq.heappop(queue) queue_time += b1 for i in range(1, len(b_array)): b0 = b_array[i] heapq.heappush(queue, -b0) queue_time += b0 while len(queue) > 0 and queue_time + base_time > T: b1 = heapq.heappop(queue) queue_time += b1 if queue_time + base_time <= T: ans = 2 * (spec_index + 1) + len(queue) answer = max(answer, ans) print(answer) if __name__ == "__main__": main()