from math import gcd from functools import cmp_to_key class Fraction: def __init__(self, top, bottom): self.top = top self.bottom = bottom def to_fraction(n): if type(n) == int: return Fraction(n, 1) else: return n def compare(L, R): L, R = to_fraction(L), to_fraction(R) a = L.top*R.bottom b = L.bottom*R.top if a < b: return -1 elif a == b: return 0 else: return 1 def max_f(L, R): return L if compare(L, R) == 1 else R def min_f(L, R): return L if compare(L, R) == -1 else R def ADD(L, R): L, R = to_fraction(L), to_fraction(R) l, r = L.bottom, R.bottom lt = L.top*r rt = R.top*l top = lt+rt bottom = l*r GCD = gcd(top, bottom) top //= GCD bottom //= GCD return Fraction(top, bottom) def SUB(L, R): L, R = to_fraction(L), to_fraction(R) l, r = L.bottom, R.bottom lt = L.top*r rt = R.top*l top = lt-rt bottom = l*r GCD = gcd(top, bottom) top //= GCD bottom //= GCD return Fraction(top, bottom) def MUL(L, R): L, R = to_fraction(L), to_fraction(R) top = L.top*R.top bottom = L.bottom*R.bottom GCD = gcd(top, bottom) top //= GCD bottom //= GCD return Fraction(top, bottom) def DIV(L, R): L, R = to_fraction(L), to_fraction(R) top = L.top*R.bottom bottom = L.bottom*R.top GCD = gcd(top, bottom) top //= GCD bottom //= GCD return Fraction(top, bottom) INF = 1<<60 N, W = map(int, input().split()) item = [list(map(int, input().split())) for _ in range(N)] L = 10**6*2 dp = [-INF]*(L+1) dp[0] = 0 for v, w in item: for i in range(L+1): if dp[i] == -INF: continue if i+w <= L: dp[i+w] = max(dp[i+w], dp[i]+v) ans = 0 if L < W: cm = cmp_to_key(compare) for i in range(N): item[i] = Fraction(*item[i]) item.sort(key=cm, reverse=True) v, w = item[0].top, item[0].bottom diff = W-L cnt = (diff+w-1)//w ans = v*cnt W -= w*cnt print(ans+max(dp[:W+1]))