#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef long double ld;typedef pair<int, int> pii;typedef vector<int> vec;typedef vector<pii> vecp;typedef vector<string> vecs;
#define dbg(a) cerr << '[' << a << ']' << '\n'
#define pb(item) push_back(item);
#define rep(i,l,n) for(int i = l; i < n; i++)
#define repd(i,l,n) for(int i = l; i >= n; i--)
#define all(a) a.begin(),a.end()
#define fc first
#define sc second
//----------------------------------------------
ll min(ll a, ll b){return a < b? a: b;}
ll max(ll a, ll b){return a > b? a: b;}
//----------------------------------------------
const ll M = 2e3+5, N = 1e9+7;
ll i,j;
//----------------------------------------------
int n,m,k,mx;
vecs t;
vec r;

void f(string s){
if(s.size()==k){
t.pb(s);
return;
}
f(s+'0');
f(s+'1');
}

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

cin >> n >> m;

vec a(m), b(m);
rep(i,0,m){
cin >> a[i] >> b[i];
}

cin >> k;

f("");

vec k1(k),k2(k);
rep(i,0,k) cin >> k1[i] >> k2[i];

rep(i,0,t.size()){
r.clear();
rep(j,0,k){
if(t[i][j] == '0'){
r.pb(k1[j]);
}else r.pb(k2[j]);
}

int cnt = 0;

rep(j,0,m){
if(find(all(r),a[j]) != r.end() && find(all(r),b[j]) != r.end()){
cnt++;
}
}
mx = max(cnt,mx);
}
cout << mx;
return 0;
}
#include<iostream>
#include<iomanip>
#include<fstream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdio>
#include<map>
#include<queue>
#include<vector>
#include<utility>
#include<ostream>
#include<istream>
#include<stack>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
#define pi acos(-1.0)
const ll maxn=1*1e6;
const ll mx=(1<<20)+99;
ll n,m,k,a[110],b[110],c[110],d[110],v[110],sum,x,y,cnt,ans,aans,num=0,sybl;
ll fpow(ll a,ll b)//a^b
{
    ll ans=1;
    while(b)
    {
        if(b%2)
        ans=ans*a%mod;
        b/=2;
        a=a*a%mod;
    }
    return ans;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int t;
//    cin>>t;
//    for(int o=1;o<=t;++o)
    {
        ans=-1;
        cin>>n>>m;
        for(int i=1;i<=m;i++)
        cin>>a[i]>>b[i];
        cin>>k;
        for(int i=1;i<=k;i++)
        cin>>c[i]>>d[i];
        for(int i=0;i<fpow(2,k);i++)
        {
            memset(v,0,sizeof(v));
            num=i;
            for(int j=1;j<=k;j++)
            {
                if(num%2)
                v[d[j]]=1;
                else
                v[c[j]]=1;
                num/=2;
            }
//            for(int j=1;j<=n;j++)
//            cout<<v[j]<<" ";
//            cout<<endl;
            aans=0;
            for(int j=1;j<=m;j++)
            {
                if(v[a[j]]&&v[b[j]])
                aans++;
            }
//            cout<<aans<<endl;
            ans=max(aans,ans);
        }
        cout<<ans<<endl;
    }
}
/*

ll hash(//ll * s,ll n)
{
    ll res=1;
    for(int i=1;i<=n;i++)
    ans=(ans+(ll)i*s[i]%mod)%mod;
    return res;
}

ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}

ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

ll fpow(ll a,ll b)//a^b
{
    ll ans=1;
    while(b)
    {
        if(b%2)
        ans=ans*a%mod;
        b/=2;
        a=a*a%mod;
    }
    return ans;
}


ll inem(ll x)//�����Ԫ
{
    ll x,y;
    exgcd(a,mod,x,y);
    return (mod+x%mod)%mod;
}

int sglfai(int n)
{
	int ans=n;
	for(int i=2;i*i<=n;i++)
	{
		if(!(n%i))
		{
			ans=ans/i*(i-1);
			for(;!(n%i);n/=i);
		}
	}
	if(n!=1)
	ans=ans/n*(n-1);
	return ans;
 }

int olnum[maxn+10];
void listfai()
{
	for(int i=1;i<=maxn;i++)
	olnum[i]=i;
	for(int i=2;i<maxn;i++)
	{
		if (olnum[i]==i)
		{
			for(int j=i;j<maxn;j+=i)
			olnum[j]=olnumn[j]/i*(i-1);
		}
	}
}

int china()
{
    int ans=0,lcm=1,x,y;
    for(int i=1;i<=k;++i)
    lcm*=m[i];
    for(int i=1;i<=k;++i)
    {
        int tmp=lcm/m[i];
        exgcd(tmp,m[i],x,y);
        x=(x%b[i]+b[i])%b[i];//xҪΪ��С�Ǹ�������
        ans=(ans+tp*x*a[i])%lcm;
    }
    return (ans+lcm)%lcm;
}

int china(int n)
{
	ll lcm=1,ans=0,mi;
	for(int i=1;i<=n;++i)
	lcm*=m[i];
	for(int i=1;i<=n;++i)
	{
		mi=lcm/m[i],ti=inem(mi,m[i]);
		ans=(ans+a[i]*mi*ti)%lcm;
	}
	return ans;
}

*/
