// C - Bowls and Dishes 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
template<class T> inline bool chmax(T& a, T& b) { if (a < b) { int tmp=a; a=b; b=tmp; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T& b) { if (a > b) { int tmp=a; a=b; b=tmp; return 1; } return 0; }
const ll mod=1000000000+7;



int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(m),b(m);
    rep(i,m){
        cin>>a[i]>>b[i];
    }
    int k;
    cin>>k;
    vector<int>c(k),d(k);
    rep(i,k){
        cin>>c[i]>>d[i];
    }

    int ans=0;
    for(int bit=0;bit<(1<<k);bit++){ // 0:put d, 1:put c
        vector<int>dishes(n);
        int cnt=0;
        for(int i=0;i<k;i++){ // k people
            if(bit&(1<<i)){
                dishes[c[i]-1]++;
            }else{
                dishes[d[i]-1]++;
            }
        }

        for(int i=0;i<m;i++){
            if(dishes[a[i]-1]>=1&&dishes[b[i]-1]>=1){
                cnt++;
            }
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;

    
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;

bool sortbysecc(const pair<int,int> &a, const pair<int,int> &b){
    return (a.second < b.second);
}

ll plates[200], ans;

void solve(ll a[], ll b[], ll c[], ll d[], ll i, ll n, ll k){
    if(i==k){
        ll cnt=0;
        for(ll j=0;j<n;j++){
            if(plates[a[j]]&&plates[b[j]]){
                cnt++;
            }
        }
        ans=max(cnt, ans);
        return;
    }
    plates[c[i]]++;
    solve(a, b, c, d, i+1, n, k);
    plates[c[i]]--;
    plates[d[i]]++;
    solve(a ,b, c, d, i+1, n, k);
    plates[d[i]]--;
}

int main()
{
    fastio;
    ll tc, n, m, k, i, j, f, caseno=1;
    cin>>n>>m;
    ll a[m], b[m];
    for(i=0;i<m;i++){
        cin>>a[i]>>b[i];
    }
    cin>>k;
    ll c[k], d[k];
    for(i=0;i<k;i++){
        cin>>c[i]>>d[i];
    }
    ans=0;
    solve(a, b, c, d, 0, m, k);
    cout<<ans;
}