#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 700;
const ll mod = 1e9+7;

#define mst(x, a) memset( x,a,sizeof(x) )
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define dep(i, a, b) for(int i=(a);i>=(b);--i)

ll read() {
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
void out(ll x) {
	int stackk[40];
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (!x) {
		putchar('0');
		return;
	}
	int top = 0;
	while (x) stackk[++top] = x % 10, x /= 10;
	while (top) putchar(stackk[top--] + '0');
}

int n,m,x[666],y[666],a[666],b[666],vis1[666],vis2[666],ans,vis[666],k;
void dfs(int pos) {
	if(pos==k+1) {
		int temp=0;
		for(int i=1; i<=m ; i++) {
			if(vis[a[i]]&&vis[b[i]]) temp++;
		}
		ans = max(ans,temp);
		return ;
	}
	vis[x[pos]]++;
	dfs(pos+1);
	vis[x[pos]]--;
	vis[y[pos]]++;
	dfs(pos+1);
	vis[y[pos]]--;
}
int main() {
	n=read(),m=read();
	rep(i,1,m) a[i]=read(),b[i]=read();
	k=read();
	rep(i,1,k) x[i]=read(),y[i]=read();
	dfs(1);
	out(ans);
	return 0;
}

/*

*/
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000007
typedef long long int ll;
typedef vector< int> vi;
typedef pair<int, int> pi;




int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);


    ll n, mm;
    cin >> n >> mm;
    vector<pair<int, int> >cond(mm);
    for (ll i = 0; i < mm; i++)
        cin >> cond[i].first >> cond[i].second;

    ll k;
    cin >> k;

    vector<pair<int, int> >choice(k);
    for (ll i = 0; i < k; i++)
        cin >> choice[i].first >> choice[i].second;

    ll ans = 0;
    for (ll i = 1; i <= (1ll << k); i++)
    {
        map<ll, ll> m;
        for (ll j = 0; j < k; j++)
        {
            if (i & (1 << j))
            {
                m[choice[j].first]++;
            }
            else
                m[choice[j].second]++;
        }
           /* */


        ll curr = 0;
        for (ll j = 0; j < mm; j++)
            if (m[cond[j].first] && m[cond[j].second])
                curr++;

        ans = max(curr, ans);
    }

    cout << ans << endl;

    return 0;
}