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()) dp2 = [0] * (sumv + 1) if V == 0: print(1) print(max(minw-1,1)) exit() for v, w in VW: tmp = INF dp3 = [0] * (sumv + 1) for i in range(sumv - v + 1): dp3[i + v] = max(dp2[i + v], dp2[i] + w) dp2 = dp3 print(dp2[V]) if len(dp2) > V + 1: print(dp2[V + 1] - 1) else: print("inf")