#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define EPS (1e-7)

constexpr int IMIN = numeric_limits<int>::min();
constexpr int IMAX = numeric_limits<int>::max();
constexpr ll LLMIN = numeric_limits<ll>::min();
constexpr ll LLMAX = numeric_limits<ll>::max();


MY_NAMESPACE(testbed)
int count_query(vector<int>& dishes, int current_k, vector<int> const& a, vector<int> const& b, vector<int> const& queried, vector<int> const& c, vector<int> const& d)
{
	if (current_k == c.size())
	{
		int ans = 0;
		for (int i = 0; i < (int)a.size(); i++)
		{
			if (dishes[a[i]] == 1 && dishes[b[i]] == 1)
				ans++;
		}
		return ans;
	}

	int this_c = c[current_k];
	int this_d = d[current_k];

	bool either_called = false;
	int ans_c = 0, ans_d = 0, ans_0 = 0;
	if (queried[this_c] == 1)
	{
		if (dishes[this_c] == 0)
		{
			vector<int> this_dishes = dishes;
			this_dishes[this_c] = 1;
			ans_c = count_query(this_dishes, current_k + 1, a, b, queried, c, d);
			either_called = true;
		}
	}
	if (queried[this_d] == 1)
	{
		if (dishes[this_d] == 0)
		{
			vector<int> this_dishes = dishes;
			this_dishes[this_d] = 1;
			ans_d = count_query(this_dishes, current_k + 1, a, b, queried, c, d);
			either_called = true;
		}
	}
	if (!either_called)
		ans_0 = count_query(dishes, current_k + 1, a, b, queried, c, d);

	int retval = ans_0;
	retval = max(retval, ans_c);
	retval = max(retval, ans_d);
	return retval;
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> b(m);
	vector<int> queried(n);
	for (int i = 0; i < m; i++)
	{
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		queried[a[i]] = 1;
		queried[b[i]] = 1;
	}

	int k;
	cin >> k;
	vector<int> c(k);
	vector<int> d(k);
	for (int j = 0; j < k; j++)
	{
		cin >> c[j] >> d[j];
		c[j]--;
		d[j]--;
	}

	vector<int> dishes(n);
	int ans = count_query(dishes, 0, a, b, queried, c, d);

	cout << ans << "\n";
	return 0;
}
MY_NAMESPACE_
#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    ll k;
    cin >> k;
    vector<ll> c(k), d(k);
    rep(i, k) {
        cin >> c[i] >> d[i];
        c[i]--;
        d[i]--;
    }

    ll ans = 0;
    rep(i, (1 << k)) {
        vector<ll> table(n);
        rep(j, k) {
            if (i & (1 << j)) {
                table[c[j]]++;
            } else {
                table[d[j]]++;
            }
        }

        ll temp = 0;
        rep(j, m) {
            if (table[a[j]] > 0 && table[b[j]] > 0) {
                temp++;
            }
        }
        ans = max(ans, temp);
    }
    cout << ans << endl;
    return 0;
}

