output_description: Print the maximum possible sum of the values of items that Taro takes home.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N W
      w_1 v_1
      w_2 v_2
      :
      w_N v_N
attempt: ######################################################
  ############Created by Devesh Kumar###################
  #############devesh1102@gmail.com####################
  ##########For CodeForces(Devesh1102)#################
  #####################2020#############################
  ######################################################
  import sys
  
  input = sys.stdin.readline
  
  # import sys
  import heapq
  import copy
  import math
  import decimal
  
  # import sys.stdout.flush as flush
  # from decimal import *
  # heapq.heapify(li)
  #
  # heapq.heappush(li,4)
  #
  # heapq.heappop(li)
  #
  # &	Bitwise AND Operator	10 & 7 = 2
  # |	Bitwise OR Operator	10 | 7 = 15
  # ^	Bitwise XOR Operator	10 ^ 7 = 13
  
  # <<	Bitwise Left Shift operator	10<<2 = 40
  # >>	Bitwise Right Shift Operator
  # '''############ ---- Input Functions ---- #######Start#####'''
  
  
  def inp():
      return int(input())
  
  
  def inlt():
      return list(map(int, input().split()))
  
  
  def insr():
      s = input()
      return list(s[: len(s) - 1])
  
  
  def insr2():
      s = input()
      return s[: len(s) - 1]
  
  
  def invr():
      return map(int, input().split())
      ############ ---- Input Functions ---- #######End
      # #####
  
  
  def pr_list(a):
      print(*a, sep=" ")
  
  
  def main():
      # tests =  inp()
      tests = 1
      mod = 998244353
      limit = 10**18
      ans = 0
      for test in range(tests):
          [n, w] = inlt()
          val = []
          maxi = 0
          for i in range(n):
              a = inlt()
              maxi = maxi + a[0]
              val.append(a)
          if w >= maxi:
              print(maxi)
              continue
          dp = [[-1 for i in range(w + 3)] for j in range(2)]
          dp[0][0] = 0
          ans = 0
          for i in range(n):
  
              for j in range(w + 3):
                  dp[(i + 1) % 2][j] = max(dp[(i + 1) % 2][j], dp[(i) % 2][j])
                  if dp[i % 2][j] != -1 and j + val[i][0] <= w:
                      dp[(i + 1) % 2][j + val[i][0]] = max(
                          dp[(i) % 2][j + val[i][0]], dp[(i) % 2][j] + val[i][1]
                      )
                      ans = max(ans, dp[(i + 1) % 2][j + val[i][0]])
          print(ans)
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N),
  Item i has a weight of w_i and a value of v_i.
  
  Taro has decided to choose some of the N items and carry them home in a
  knapsack. The capacity of the knapsack is W, which means that the sum of the
  weights of items taken must be at most W.
  
  Find the maximum possible sum of the values of items that Taro takes home.
samples: [{"input": "3 8\n    3 30\n    4 50\n    5 60", "output": "90\n    \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n    1000000000 10", "output": "10\n    \n\n* * *"}, {"input": "6 15\n    6 5\n    5 6\n    6 4\n    6 6\n    3 5\n    7 2", "output": "17\n    \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]