/** This won't be the end of me */

#include <iostream>
#include <algorithm>

#define endl '\n'
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int mx, k, m, n;
int a[100], b[100], c[16], d[16], dish[101];

void loop()
{
    int cnt = 0;
    for(size_t i = 0; i < m; ++i)
    {
        if(dish[a[i]] && dish[b[i]])
            ++cnt;
    }
    mx = max(mx, cnt);
//    cout << "max == " << mx << endl;
}

void check(int row, bool val)
{
    val == true ? ++dish[d[row]] : ++dish[c[row]];

//    cout << "incremented " << (val == true? d[row] : c[row]) << endl;

    if(row == k-1) // base case
        loop();
    if(row+1 < k)
    {
        check(row+1, false);
        check(row+1, true);
    }


    val == true ? --dish[d[row]] : --dish[c[row]];

//    cout << "decremented " << (val == true? d[row] : c[row]) << endl;

}

void solve()
{
    int i, j, l;

    cin >> n >> m;

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

    cin >> k;

    for(i = 0; i < k; ++i)
        cin >> c[i] >> d[i];

    check(0, false); // activate c[row]
    check(0, true); //  activate d[row]

    cout << mx;

}


int main()
{
    FAST

//    int t; cin >> t; while(t--){
        solve();
//    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define Please return
#define AC 0
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	//cout << fixed << setprecision(10);
    int n,m; cin >> n >> m;
    vi a(m),b(m);
    rep(i,0,m)cin >> a[i] >> b[i];
    int k; cin >> k;
    vi c(k),d(k);
    rep(i,0,k){
        cin >> c[i] >> d[i];
    }
    int ans = 0;
    rep(i,0,(1<<k)){
        int tmp = 0;
        vi v(n);
        rep(j,0,k){
            if(i>>j&1){
                v[d[j]-1] = 1;
            }
            else{
                v[c[j]-1] = 1;
            }
        }
        rep(i,0,m){
            tmp += (v[a[i]-1]&&v[b[i]-1]);
        }
        chmax(ans,tmp);
    }
    cout << ans << endl;

	Please AC;
}