n, W = map(int, input().split()) items = [tuple(map(int, input().split())) for _ in range(n)] # Initialize DP array for 0-1 knapsack dp = [0] * (W + 1) # Process each item to update the DP array for w_i, v_i in items: for w in range(W, w_i - 1, -1): if dp[w - w_i] + v_i > dp[w]: dp[w] = dp[w - w_i] + v_i # Update the DP array to take cumulative maximum for w in range(1, W + 1): if dp[w] < dp[w - 1]: dp[w] = dp[w - 1] max_original = dp[W] # Calculate the minimum V for each X from 1 to W for X in range(1, W + 1): available = W - X prev_val = dp[available] if available >= 0 else 0 V = max_original - prev_val + 1 print(V)