N = int(input()) item = [list(map(int, input().split())) for _ in range(N)] V = int(input()) dp = [[0]*(10**5+1) for _ in range(N+1)] sm_v, sm_w = 0, 0 for i in range(1, N+1): v, w = item[i-1] sm_v += v sm_w += w for j in range(10**5+1): if j>=w: dp[i][j] = max(dp[i-1][j-w]+v, dp[i][j]) dp[i][j] = max(dp[i][j], dp[i-1][j]) for i in range(1,10**5+1): if dp[-1][i] == V: print(i) break if dp[-1][sm_w] == V: print('inf') else: for i in range(10**5, 0, -1): if dp[-1][i] == V: print(i) break