#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n1;
    cin>>n1;
    vector<pair<int,int>> a1(n1);
    int i,j;
    for(i=0;i<n1;i++){
        cin>>a1[i].first;
        cin>>a1[i].second;
    }
    sort(a1.begin(),a1.end());
    int n2;
    cin>>n2;
    vector<pair<int,int>> a2(n2);
    for(i=0;i<n2;i++){
        cin>>a2[i].first;
        cin>>a2[i].second;
    }
    sort(a2.begin(),a2.end());
    int masa;
    cin>>masa;

    vector<int> pref2(n2+1);
    pref2[0]=0;
    for(i=1;i<=n2;i++){
        if(pref2[i-1]>a2[i-1].second){
            pref2[i]=pref2[i-1];
        }
        else{
            pref2[i]=a2[i-1].second;
        }
    }
    j=n2-1;
    i=0;
    int maxx=0;
    while(i<n1 && j>=0){
        while(j>=0 && masa<a1[i].first+a2[j].first){
            j--;
        }
        if(j>=0 && a1[i].second+pref2[j+1]>maxx){
            maxx=a1[i].second+pref2[j+1];
        }
        i++;
    }
    cout<<maxx<<endl;
    return 0;
}
