N,W = map(int,input().split()) mx = 10**5 dp = [[-1]*(mx+3) for _ in range(N+3)] dp[0][0] = 0 for i in range(N): w,v = map(int,input().split()) for j in range(mx+1): if dp[i][j] == -1: continue dp[i+1][j] = max(dp[i][j], dp[i+1][j]) if j+w <= mx: dp[i+1][j+w] = max(dp[i][j]+v, dp[i+1][j+w]) Vmax = max(dp[N][:W+1]) for j in range(1,mx+1): dp[N][j] = max(dp[N][j-1], dp[N][j]) for x in range(1,W+1): rem = W - x Vtmp = dp[N][rem] Vbob = (Vmax - Vtmp) + 1 print(Vbob) #for i in range(N+3): # print(*dp[i][:W+3])