#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int mx=2000;
const int mod= 1e9+7;
const ll inf=1e12+4;


int arr[6]={4,8,15,16,23,42};
int cnt[100];
int a[mx];int b[mx];int aa[mx];int bb[mx];
int k;int n,m;
int ok[mx];
int ans=0;

void solve(int i){
if(i==k){
    int l=0;
    for(int j=0;j<m;j++){
        if(ok[a[j]]&&ok[b[j]]){l++;}
    }ans=max(ans,l);
    return;
}
ok[aa[i]]++;
solve(i+1);
ok[aa[i]]--;
ok[bb[i]]++;
solve(i+1);ok[bb[i]]--;
return ;
}
int main() {

   int t;
   //cin>>t;
   t=1;
   while(t--){


cin>>n>>m;

for(int i=0;i<m;i++){
   cin>>a[i]>>b[i];

    }cin>>k;
    for(int i=0;i<k;i++){
   cin>>aa[i]>>bb[i];

    }
    solve(0);cout<<ans;

}



}





#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (ll i = 0; i < (o); ++i)
#define REP(i,a,b)for(ll i=(ll)(a);(i)<(ll)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ll n, m; cin >> n >> m;
    vector<pair<ll, ll>> b(m); 
    rep(j, m) { 
        cin >> b[j].first >> b[j].second;
        b[j].first--; b[j].second--;
    }

    ll k; cin >> k;
    vector<ll> c(k), d(k); 
    rep(i, k) {
        cin >> c[i] >> d[i];
        c[i]--; d[i]--;
    }
    ll ans = 0;
    for (ll bit = 0; bit < (1 << k); bit++)
    {
        ll cnt = 0;
        vector<bool> selected(n);
        rep(j, k) {
            if (bit & (1 << j)) selected[d[j]] = true;
            else selected[c[j]] = true;
        }
        // rep(j, n) { 
        //     cout << selected[j] << endl;
        // }
        rep(i, m) {
            if (selected[b[i].first] && selected[b[i].second]) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}