// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define dd double
#define ld long double
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define sd(n) scanf("%lf", &n)
#define pll pair <ll, ll>
#define pii pair <int, int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define inf (1LL << 61)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define for1(i, stop) for(ll i = 1; i <= stop; ++i)
#define for0(i, stop) for(ll i = 0; i < stop; ++i)
#define rep1(i, start) for(ll i = start; i >= 1; --i)
#define rep0(i, start) for(ll i = (start-1); i >= 0; --i)
#define ms(n, i) memset(n, i, sizeof(n))
#define casep(n) printf("Case %lld:", ++n)
#define pn printf("\n")
#define pf printf
#define EL '\n'
#define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const ll sz = 110;
ll ans, cnt[sz], c[sz], d[sz], a[sz], b[sz], n, m, k;

void solve(ll pos)
{
    if(pos > k) {
        ll tot = 0;
        for1(i, m) {
            if(cnt[ a[i] ] >= 1 && cnt[ b[i] ] >= 1)
                tot++;
        }
        ans = max(ans, tot);
        return;
    }

    cnt[ c[pos] ]++;
    solve(pos+1);
    cnt[ c[pos] ]--;

    cnt[ d[pos] ]++;
    solve(pos+1);
    cnt[ d[pos] ]--;
}

int main()
{
    cin >> n >> m;
    for1(i, m) {
        sl(a[i]), sl(b[i]);
    }

    cin >> k;
    for1(i, k) {
        sl(c[i]), sl(d[i]);
    }

    solve(1);

    cout << ans << EL;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    int n,m;
  	int vdncjdkdkh; 
    cin>>n>>m;
    vector<pair<int,int>>a(m);
    for(int i=0;i<m;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    int k;
    cin>>k;
    vector<pair<int,int>>b(k);
    for(int j=0;j<k;j++)
    {
        cin>>b[j].first>>b[j].second;
    }
    ll l=0;
    ll tot=1<<k;
    for(ll mask=0;mask<tot;mask++)
    {
        vector<int>v(n+1);
        ll ans=0;
        for(int i=0;i<k;i++)
        {
            if(mask & (1<<i))
                v[b[i].second]=1;
            else
                v[b[i].first]=1;
        }
        for(int i=0;i<m;i++)
        {
            if(v[a[i].first] && v[a[i].second])
                ans++;
        }
        l=max(l,ans);
    }
    cout<<l<<endl;
    return 0;
}