#include <bits/stdc++.h>          
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}

int main() {
    ll N, M; cin >> N >> M;
    vector<pair<ll,ll>> m(M);
    rep(i,M) {
        ll a, b; cin >> a >> b;
        a--; b--;
        m[i] = {a,b};
    }
    ll K; cin >> K;
    vector<pair<ll,ll>> k(K);
    rep(i,K) {
        ll c, d; cin >> c >> d;
        c--; d--;
        k[i] = {c,d};
    }

    ll ans = 0;
    rep(bit,1<<K) {
        vector<ll> vec(N);
        rep(i,K) {
            ll x = k[i].first, y = k[i].second;
            if ((bit>>i)&1) vec[x]++;
            else vec[y]++;
        }
        ll cnt = 0;
        rep(i,M) {
            ll x = m[i].first, y = m[i].second;
            if (vec[x]>=1 && vec[y]>=1) cnt++;
        }
        ans = max(ans,cnt);
    }

    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;

int main () {
	 ios::sync_with_stdio(false);
	 cin.tie(nullptr);
	 cout.tie(nullptr);
	 int T = 1;
	 //~ cin >> T;
	 for (int test_case = 1; test_case <= T; ++test_case) {
		 int n,m;
		 cin >> n >> m;
		 pair<int,int> a[m + 1];
		 for (int i = 1; i <= m; ++i) cin >> a[i].first >> a[i].second;
		 int k;
		 cin >> k;
		 pair<int,int> b[k + 1];
		 int res = 0;
		 for (int i = 1; i <= k; ++i) cin >> b[i].first >> b[i].second;
		 for (int bit = 0; bit < (1 << k); ++bit) {
			 int count[n + 1];
			 for (int i = 1; i <= n; ++i) count[i] = 0;
			 for (int i = 1; i <= k; ++i) {
				 if (bit & (1 << (i - 1))) {
					 ++count[b[i].second];
				 } else {
					 ++count[b[i].first];
				 }
			 }
			 int total = 0;
			 for (int i = 1; i <= m; ++i) {
				 total += (count[a[i].first] and count[a[i].second]);
			 }
			 res = max(res,total);
		 }
		 cout << res << '\n';
	 }
	 //cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}
