import sys input = sys.stdin.readline N,M=map(int,input().split()) X=[list(map(int,input().split())) for i in range(N)] X.sort(reverse=True) X.sort(key=lambda x:x[0]/x[1],reverse=True) Y=X[:-20] REST=X[-20:] ANS=0 for v,w in Y: if w<=M: ANS+=v M-=w Q=[(0,0)] for v,w in REST: NQ=[] for x,y in Q: if w+y<=M: NQ.append((v+x,w+y)) Q+=NQ MAX=0 for x,y in Q: MAX=max(MAX,x) print(ANS+MAX)