from collections import defaultdict from itertools import accumulate import bisect N,T = list(map(int,input().split())) pro = defaultdict(list) for _ in range(N): a,b = list(map(int,input().split())) pro[a].append(b) two = [] for i in pro: MIN = min(pro[i]) pro[i].remove(MIN) two.append(MIN) two.sort() one = sorted([j for i in pro for j in pro[i]]) SS = [0] + list(accumulate(two)) S = [0] + list(accumulate(one)) ans = 0 for i in range(len(two)+1): now = SS[i] if(now > T):break place = bisect.bisect_right(S, T - now) - 1 assert now + S[place] <= T ans = max(ans, 2*i + place) print(ans)