N = int(input()) VW = [] sumv = 0 INF = 10 ** 6 minw = INF for i in range(N): v, w = map(int, input().split()) sumv += v VW.append((v, w)) minw = min(w,minw) VW.sort(reverse = True) V = int(input()) dp = [INF] * (sumv + 1) dp[0] = 0 dp2 = [0] * (sumv + 1) for v, w in VW: for i in reversed(range(sumv - v + 1)): dp[i+v] = min(dp[i+v],dp[i]+w) y = 0 x = max(dp[V],1) if dp[V+1:]: y = min(dp[V+1:]) - 1 print(x) if x > y: print("inf") else: print(y)