#include <bits/stdc++.h>
using namespace std;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> cond(m);
	for (auto &[a, b] : cond) cin >> a >> b;
	int k;
	cin >> k;
	vector<pair<int, int>> choice(k);
	for (auto &[c, d] : choice) cin >> c >> d;
	int res = 0;
	for (int mask = 0; mask < (1 << k); ++mask) {
		vector<bool> ball(n);
		for (int i = 0; i < k; ++i) {
			auto &[c, d] = choice[i];
			ball[(mask & (1 << i)) ? c : d] = true;
		}
		int cnt = 0;
		for (auto &[a, b] : cond) {
			if (ball[a] && ball[b]) cnt++;
		}
		res = max(res, cnt);
	}
	cout << res << endl;
}

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

int check(vector<vector<int>> pairs, vector<bool> put) {
	int ans = 0;
	for (int i = 0; i < pairs.size(); i++) {
		if (put.at(pairs.at(i).at(0)-1) and put.at(pairs.at(i).at(1)-1)) {
			ans++;
		}
	}
	return ans;
}

int maxjoken(vector<vector<int>> pairs, vector<bool> put,vector<vector<int>> options,int rest,int N) {
	if (rest == 0) {
		return check(pairs, put);
	}
	vector<bool> a=put, b=put;
	a.at(options.at(N - rest).at(0)-1) = true;
	b.at(options.at(N - rest).at(1)-1) = true;
	return max(maxjoken(pairs, a, options, rest - 1, N), maxjoken(pairs, b, options, rest - 1, N));
}



int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> pairs(M, vector<int>(2));
	for (int i = 0; i < M; i++) {
		cin >> pairs.at(i).at(0);
		cin >> pairs.at(i).at(1);
	}
	int K;
	cin >> K;
	vector<vector<int>> options(K,vector<int>(2));
	for (int i = 0; i < K; i++) {
		cin >> options.at(i).at(0) >> options.at(i).at(1);
	}
	vector<bool> put(N, false);
	cout << maxjoken(pairs, put, options, K, K);
}