n1=int(input())
a1=[]
for i in range(n1):
    m,c=input().split()
    l=[]
    l.append(int(m))
    l.append(int(c))
    a1.append(l)
a1=sorted(a1)
n2=int(input())
a2=[]
for i in range(n2):
    m,c=input().split()
    l=[]
    l.append(int(m))
    l.append(int(c))
    a2.append(l)
a2=sorted(a2)
masa=int(input())

pref2=[0]
for i in range(n2):
    if pref2[i]>a2[i][1]:
        pref2.append(pref2[i])
    else:
        pref2.append(a2[i][1])

i=0
j=n2-1
res=0
while i<n1 and j>=0:
    while j>=0 and a2[j][0]+a1[i][0]>masa:
        j-=1
    if j>=0 and a1[i][1]+pref2[j+1]>res:
        res=a1[i][1]+pref2[j+1]
    i+=1
print(res)


    
