#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll> 
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<=e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
ll MOD = 1e9 + 7;
//ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);} 
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}
void solve(){
    ll n, m;
    cin >> n >> m;
    ll a[m][2];
    fo(i, m){
        cin >> a[i][0] >> a[i][1];
    }
    ll k;
    cin >> k;
    
    ll c[k][2];
    fo(i, k){
        cin >> c[i][0] >> c[i][1];
    }
    ll ans = 0;
    ll tot = (1LL << k);
    fo(i, tot){
        vll ok(n + 1);
        fo(j, k){
            if((i >> j) & 1){
                ok[c[j][1]] = 1;
            }
            else{
                ok[c[j][0]] = 1;
            }
        }
        ll cnt = 0;
        fo(j, m){
            if(ok[a[j][0]] && ok[a[j][1]]){
                cnt++;
            }
        }
        ans = max(ans, cnt);
    }
    ANS;
}
int main(){ 
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin) ;
    freopen("output.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll TC = 1;
    //cin>>TC;
    fo(TT, TC){
        // Google,FB cout << "Case #"<< TT + 1 << ": ";
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define pf                push_front
#define ppf               pop_front
#define ppb               pop_back
#define ff                first
#define s(num)            to_string(num)
#define ss                second
#define mp(a,b)           make_pair(a,b)
#define pii               pair<int,int>
#define vi                vector<int>
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ssort(v)          sort(v.begin(),v.end())
#define rsort(v)          sort(v.rbegin(),v.rend())
#define start(t)          int x;cin>>x;while(x--)
#define endl              "\n"
#define all(x)            (x).begin(),(x).end()

void rec(vector<pii>& v, vector<pii>& p, int &cnt, int idx, unordered_map<int, int> um) {
    if (idx >= p.size()) {
        int q = 0;
        for (pii x : v) {
            if (um[x.ff] && um[x.ss])
                q += 1;
        }
        cnt = max(cnt, q);
        return;
    }
    um[p[idx].ff] += 1;
    rec(v, p, cnt, idx + 1, um);
    um[p[idx].ff] -= 1;
    um[p[idx].ss] += 1;
    rec(v, p, cnt, idx + 1, um);
    um[p[idx].ss] -= 1;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
#ifdef NCR
    init();
#endif
    int n, m; cin >> n >> m;
    vector<pii> v;
    for (int i = 0; i < m; i++) {
        int x, y; cin >> x >> y;
        v.pb(mp(x, y));
    }
    int k; cin >> k;
    vector<pii> p;
    unordered_map<int, int> um;
    for (int i = 0; i < k; i++) {
        int a, b;
        cin >> a >> b;
        p.push_back(mp(a, b));
    }
    int cnt = INT_MIN;
    rec(v, p, cnt, 0, um);
    cout << cnt << endl;
}