import numpy as np N = int(input()) MAX = 100000 dp = np.zeros(MAX + 1, dtype=int) ans_min = MAX + 1 ans_max = 0 for _ in range(N): v, w = map(int, input().split()) dp[w:] = np.maximum(dp[w:], dp[:-w] + v) V = int(input()) l = np.searchsorted(dp, V, side='left') r = np.searchsorted(dp, V, side='right') print(l if l > 0 else 1) print('inf' if r - 1 == MAX else r - 1)