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