def solve(): N, W = map(int, input().split()) vw = [list(map(int, input().split())) for _ in range(N)] dp = [-1]*(W+1) dp[0] = 0 for v, w in vw: for j in range(W, w-1, -1): if dp[j-w] != -1: dp[j] = max(dp[j], dp[j-w] + v) print(max(dp)) solve()