// 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 all(x) (x).begin(),(x).end()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(all(x)),x.end())
typedef long long ll;
typedef pair<int,int> P;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll fpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

unordered_map<int,int> M;
int n,m,k;
int ans = 0,res = 0;
void dfs(int s, vector<P> &a,vector<P> &b){
    if(s > k) {
        for(int i = 1;i<=m;i++){
            int fi = a[i].first;
            int se = a[i].second;
            if(M[fi] > 0 && M[se] > 0) {
                ans++;
            }
        }
        res = max(ans,res);
        ans = 0;
        //cout << M[1] << " " << M[2] << " " << M[3] << " " << M[4] << endl;
        return ;
    }

    M[b[s].first]++;
    dfs(s + 1,a,b);
    M[b[s].first]--;
    M[b[s].second]++;
    dfs(s + 1,a,b);
    M[b[s].second]--;
    
}
int main(){
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin >> n >> m;
    vector<P> a(m+1);
    for(int i = 1;i<=m;i++){
        cin >> a[i].first >> a[i].second;
    }
    cin >> k;
    vector<P> b(k+1);
    for(int i = 1;i<=k;i++){
        cin >> b[i].first >> b[i].second;
    }
    dfs(1,a,b);
    cout << res << endl;
    return 0;
}

