You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i.  You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W.  Your objective is to maximize the total value of the selected items.
N, W = map(int, input().split())
wl = [0]*N
vl = [0]*N
for i in range(N):
  wl[i], vl[i] = map(int, input().split())

dp = {}
for i in range(N):
  w, v = wl[i], vl[i]

  newdp = {}
  if w not in dp:
    newdp[w] = v
  else:
    newdp[w] = max(dp[w], v)

  
  for ew, ev in dp.items():
    if ew not in newdp:
      newdp[ew] = ev
    else:
      newdp[ew] = max(dp[ew], ev)
    
    if ew + w not in newdp:
      newdp[ew+w] = ev+v
    else:
      newdp[ew+w] = max(dp[ew+w], ev + v)
  dp = newdp

ans = 0
for w, v in dp.items():
  if w <= W:
    ans = max(ans, v)
print(ans)
print(dp)


# 	return [[0 for i in range(m)] for j in range(n)]

N, W = map(int, input().split())
wl = [0]*N
vl = [0]*N
for i in range(N):
  wl[i], vl[i] = map(int, input().split())

dp = {}
for i in range(len(wl)):
  w, v = wl[i], vl[i]

  newdp = {}
  
  # copy
  for ew, ev in dp.items():
    if ew not in newdp:
      newdp[ew] = ev
    else:
      newdp[ew] = max(newdp[ew], ev)

    if ew + w not in newdp:
      newdp[ew+w] = ev+v
    else:
      newdp[ew+w] = max(newdp[ew+w], ev + v)

  
  if w not in newdp:
    newdp[w] = v
  else:
    newdp[w] = max(newdp[w], v)
    
  dp = newdp

ans = 0
for w, v in dp.items():
  if w <= W:
    ans = max(ans, v)
print(ans)


