#include<bits/stdc++.h>
using namespace std;
const int N = 200+5;
#define esp 1e-19
#define ll long long
#define inf 0x3f3f3f3f
 
int a[N][N],b[N];
struct node {
    int x,y;
}c[N];
int n,m,k;
int ret;
int vis[N][N];
void DFS(int r) {
    if(r==k) {
        int cnt = 0;
        memset(vis,0,sizeof vis);
        for(int i = 0;i < k;i++) {
            for(int j = 0;j < k;j++) {
                if(vis[b[i]][b[j]]==0) {
                    cnt+=a[b[i]][b[j]];
                    vis[b[i]][b[j]] = 1;
                }
            }
        }
        ret = max(ret,cnt);
        return;
    }
    b[r] = c[r].x;
    DFS(r+1);
    b[r] = c[r].y;
    DFS(r+1);
}
int main() {
    cin>>n>>m;
    for(int i = 0,u,v;i < m;i++) {
        cin>>u>>v;
        a[u][v]++;
    }
    cin>>k;
    for(int i = 0;i < k;i++) {
        cin>>c[i].x>>c[i].y;
    }
    DFS(0);
    cout<<ret<<endl;
}
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<ll,ll> pll;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//#define ordered_set tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update>

#define vint vector<int>
#define vll vector<long long>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define F(i,n) for(int i = 0;i<n;i++)
#define Fr(i,l,r) for(int i = l;i <= r;i++)
#define rF(i,n) for(int i = n-1;i>=0;i--)
#define Max 1000001
#define intinf 2147483647
#define longlonginf 9223372036854775807
#define MOD 998244353
#define MOD2 1000000007
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(arr) arr.begin(),arr.end()
//#define sort(vec) sort(vec.begin(),vec.end())
//#define reverse(vec) reverse(vec.begin(),vec.end())

ll Lpow(ll a,ll b)
{
    ll ans = 1;
    while(b > 0)
    {
        if(b%2)
            ans = (ans*a);
        a = (a*a);
        b = b/2;
    }
    return ans;
}

ll Lpow(ll a,ll b,ll M)
{
	ll ans = 1;
	while(b > 0)
	{
		if(b%2)
			ans = (ans*a)%M;
		a = (a*a)%M;
		b = b/2;
	}
	return ans;
}


int main()
{
    fastio;

    int n,m;
    cin >> n >> m;

    vector<int> arr(m),brr(m);

    F(i,m)
        cin >> arr[i] >> brr[i];

    int k;
    cin >> k;

    vector<int> crr(k),drr(k);
    F(i,k)
        cin >> crr[i] >> drr[i];

    int ma = (1<<k)-1;
    int ans = 0;

    for(int i = 0;i<=ma;i++)
    {
        vector<int> tmp(n+1,0);

        int o = i;
        for(int u = 0;u < k;u++)
        {
            if((o&(1<<u)) >= 1)
                tmp[drr[u]]++;
            else
                tmp[crr[u]]++;
        }

        int curr = 0;
        for(int j = 1;j<=m;j++)
        {
            if(tmp[arr[j-1]] >= 1 && tmp[brr[j-1]] >= 1)
                curr++;
        }

        ans = max(ans,curr);
    }

    cout << ans << endl;

	return 0;
}
