import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) VW=[tuple(map(int,input().split())) for _ in range(n)] vmax=int(input()) DP=[0]*1001 for i in range(n): v,w=VW[i] for j in range(1001)[::-1]: if j