import sys input = sys.stdin.readline from operator import itemgetter N,M=map(int,input().split()) X=[list(map(int,input().split())) for i in range(N)] M0=M X.sort(reverse=True) X.sort(key=lambda x:x[0]/x[1],reverse=True) ANS=0 LASTS=[] for i in range(len(X)): v,w=X[i] if w<=M: ANS+=v M-=w LASTS.append((i,ANS,M)) MMAX=0 for tests in range(25,1000,25): if len(LASTS)=x: continue else: Q2.append((x,y)) Q=Q2 MAX=0 for x,y in Q: MAX=max(MAX,x) if MAX!=MMAX: MMAX=MAX else: break print(ANS+MMAX)