INF = 1 << 60 n = int(input()) items = [list(map(int, input().split())) for _ in range(n)] v = int(input()) dp = {} dp[0] = 0 for vi, wi in items: ndp = {} for value, weight in dp.items(): ndp[value] = min(ndp.get(value, INF), weight) if value <= v: ndp[value + vi] = min(ndp.get(value + vi, INF), weight + wi) dp = ndp cands = list(dp.items()) cands.sort(key=lambda x: - x[1]) m = 100001 score = [0] cands.pop() for _ in range(m): score.append(score[-1]) if len(cands) > 0 and len(score) - 1 == cands[-1][1]: score[-1], _ = cands.pop() lb = INF ub = - INF for x in range(1, m + 1): if score[x] == v: lb = min(lb, x) ub = max(ub, x) print(lb) if ub < m: print(ub) else: print("inf")