#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define pi acos(-1.0)
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
 
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
 
//#define inf 1<<30
 
// isupper() -> upper case check
// tolower() -> convert upper to lower case
// idx = str.find("bear", pos)) != string::npos =>substring find
// Tuple access -> get<0>(v[i])
// cmnt - ctrl []
// stoi("...") -> decimel
// istringstream ss(str) while(ss >> n)
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;
 
const ll inf = 1e18+100;
const ll mod = 1e9+7;
 
int dr[] = {-1, 0, 1,  0};// up, right, down, left
int dc[] = { 0, 1, 0, -1};
 
// King moves similar to 8 direction
//int dr[] = {-1, -1, 0, 1, 1,  1, 0, -1};
//int dc[] = { 0,  1, 1, 1, 0, -1,-1, -1};
 
// Knight moves
int kr[] = {-1,  1, -2, -2, -1, 1,  2,  2};
int kc[] = {-2, -2, -1,  1,  2, 2, -1,  1};
// diagonal moves
int dgr[] = {-1, -1,  1, 1};
int dgc[] = { 1, -1, -1, 1};

int ans, k;
vector<pii>v, ara;
int cnt[111];

void fun(int idx)
{
    if(idx == k) {
        int cur = 0;
        for(pii p: ara) {
            //printf("%d %d\n", p.ff, cnt[p.ff]);
            if(cnt[p.ff] >= 1 && cnt[p.ss] >= 1) cur++;
        }
        ans = max(ans, cur);
        return;
    }

    int x = v[idx].ff;
    ++cnt[x];
    fun(idx+1);
    --cnt[x];

    int y = v[idx].ss;
    ++cnt[y];
    fun(idx+1);
    --cnt[y];
    return;
}
 
void solve()
{
    int n, m;
    cin >> n >> m;
    //vector<pii>ara;

    for(int i=0; i<m; i++) {
        int x, y;
        cin >> x >> y;
        ara.pb({x, y});
    }
    //int k;
    cin >> k;

    //int cnt[n*n];
    //memset(cnt, 0, sizeof cnt);

    for(int i=0; i<k; i++) {
        int x, y;
        cin >> x >> y;

        v.pb({x, y});
        //if(!cnt[x]) cnt[x] = 1;
        //else cnt[y]++;
    }

    //int ans = 0;

    fun(0);

    cout << ans << endl;
}
 
int main()
{
    fast_io;
 
    int tt = 1;
    //cin >> tt;
 
    while(tt--) {
        solve();
    }
 
    return 0;
}
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> a(m),b(m);
	rep(i,m) cin >> a[i] >> b[i];
	int k;
	cin >> k;
	vector<int> c(k),d(k);
	rep(i,k) cin >> c[i] >> d[i];
	int ans = 0;
	rep(is,1<<k){
		int sum = 0;
		vector<int> sara(n+1);
		rep(i,k){
			if(is>>i&1)sara[d[i]]++;
			else sara[c[i]]++;
		}
		rep(i,m){
			if(sara[a[i]] == 0) continue;
			if(sara[b[i]] == 0) continue;
			sum++;
		}
		ans = max(ans,sum);
	}
	cout << ans << endl;
	return 0;
}

// cout << fixed << setprecision(15) <<  << endl;
