#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long 
#define vl vector<ll>
#define vs vector<string>
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define sl set<ll>
#define pql priority_queue<ll>

#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define REP(i,a,b) for(i=a;i<b;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(), a.rend()
#define vsort(a) sort(all(a))
#define rvsort(a) sort(rall(a))

#define F first
#define S second
#define pi acos(-1)
#define inf 10000000000000000
#define mod 1000000007
#define MA LLONG_MAX
#define MI LLONG_MIN

long long power(long long x,ll y)
{
    long long res = 1; 
    x = x % mod;
    while (y > 0) 
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1; 
        x = (x * x) % mod;
    }
    return res;
}

long modInverse(long long n)
{
    return power(n, mod - 2);
}

long long ncr(long long n, ll r)
{
    if (n < r)
        return 0;
    if (r == 0)
        return 1;
    long long fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % mod;
 
    return (fac[n] * modInverse(fac[r]) % mod*modInverse(fac[n - r])% mod)% mod;
}
 

void solve()
{
    ll n,m,i,j,ans=0,fans=0;
    cin>>n>>m;
    vl a(m),b(m);
    rep(i,m)
    cin>>a[i]>>b[i];
    ll k;
    cin>>k;
    vl c(k),d(k);
    rep(i,k)
    {
        cin>>c[i]>>d[i];
    }
    ll temp=pow(2,k)-1;
    for(i=0;i<=temp;i++)
    {
        bitset<20> bb(i);
        vl count(n+1,0);
        ans=0;
        for(j=0;j<k;j++)
        {
            if(bb[j]==0)
            count[c[j]]++;
            else
            count[d[j]]++;
        }
        for(j=0;j<m;j++)
        {
            if(count[a[j]]>0&&count[b[j]]>0)
            ans++;
        }
        //cout<<ans<<" ";
        fans=max(fans,ans);
    }
    cout<<fans<<endl;
}
    
int32_t main() {
	ios_base::sync_with_stdio(false);
   cin.tie(NULL); cout.tie(NULL);
// #ifdef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	
	int t=1;
	//cin>>t;
	while (t--) {
		solve();
	}
	return 0;
}
#include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 300005
#define MOD 1000000007
#define GMAX 19
#define INF 20000000000000000
#define EPS 0.000000001
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int dishes[MAX];
pair<int,int> conditions[MAX];
int add[20][2];
int ans;
void backtrack(int index,int k,int m)
{
    int i;
    if(index==k)
    {
        int curr=0;
        for(i=0;i<m;i++)
        {
            curr=curr+(dishes[conditions[i].first]>0&&dishes[conditions[i].second]>0);
        }
        ans=max(ans,curr);
        return;
    }
    for(i=0;i<2;i++)
    {
        dishes[add[index][i]]++;
        backtrack(index+1,k,m);
        dishes[add[index][i]]--;
    }
}
int main()
{
    int n,m,k,i,j;
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++)
    {
        scanf("%d %d",&conditions[i].first,&conditions[i].second);
    }
    scanf("%d",&k);
    for(i=0;i<k;i++)
    {
        for(j=0;j<2;j++)
        {
            scanf("%d",&add[i][j]);
        }
    }
    backtrack(0,k,m);
    printf("%d",ans);
    return 0;
}
