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

#define INF 0x3f3f3f3f
#define endl '\n'
#define ll long long
#define mp make_pair
typedef pair<int, int> ii;

int solution(vector<int> dp, const int& level, const int& k, const vector<ii>& options, const vector<vector<int>>& cond){
	if(level == k) return 0;
	int opt1 = options[level].first;
	int opt2 = options[level].second;
	int inc1 = 0, inc2 = 0;
	vector<int> dp2 = dp;
	if(dp[opt1] == 0){
		dp[opt1] = 1;
		for(int dish: cond[opt1]){
			if(dp[dish] == 1) ++inc1;
		}
	}
	if(dp2[opt2] == 0){
		dp2[opt2] = 1;
		for(int dish: cond[opt2]){
			if(dp2[dish] == 1) ++inc2;
		}
	}
	return max(solution(dp, level+1, k, options, cond) + inc1, solution(dp2, level+1, k, options, cond) + inc2);
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << setprecision(2) << fixed;
	
	int n, m;
	cin >> n >> m;
	vector<vector<int>> cond(n+1);
	while(m--){
		int a, b;
		cin >> a >> b;
		cond[a].push_back(b);
		cond[b].push_back(a);
	}
	int k, copy;
	cin >> k;
	copy = k;
	vector<ii> options;
	while(copy--){
		int c, d;
		cin >> c >> d;
		options.push_back(mp(c, d));
	}
	vector<int> dp(n+1, 0);
	dp[0] = -1;
	cout << solution(dp, 0, k, options, cond);
	return 0;
}
#include <iostream>
using namespace std;

struct choice {
  int a = 0;
  int b = 0;
};

int count(bool *D, int N, struct choice *C, int M) {
  int ans = 0;
  for (int i = 0; i < M; i++) {
    int a = C[i].a;
    int b = C[i].b;
    if (D[a] && D[b]) {
      ans++;
    }
  }
  return ans;
}

int main() {
  int N, M, K, ans;
  cin >> N;
  cin >> M;

  struct choice C[M]; // conditions
  for (int i = 0; i < M; i++) {
    cin >> C[i].a;
    cin >> C[i].b;
  }

  cin >> K;
  struct choice V[K]; // votes
  for (int i = 0; i < K; i++) {
    cin >> V[i].a;
    cin >> V[i].b;
  }

  ans = 0;
  for (int n = 0; n < (1 << K); n++) {
    bool D[N + 1] = {}; // dishes
    for (int k = 0; k < K; k++) {
      int v = n & (1 << k); // mask
      int i = v ? V[k].a : V[k].b;
      D[i] = 1;
    }
    int sum = count(D, N + 1, C, M);
    if (ans < sum) {
      ans = sum;
    }
  }

  cout << ans;

  return 0;
}
