#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

int main() {
  int n, m, k;
  int N[100] = {0};
  pair<int, int> K[17], M[101];

  function<int(int)> rec = [&](int i) {
    if (i == k) {
      int cnt = 0;
      for (int j = 0; j < m; ++j) {
        auto[f, s] = M[j];
        if (N[f] && N[s]) cnt++;
      }
      return cnt;
    }

    auto[f, s] = K[i];
    N[f]++;
    int sum1 = rec(i + 1);
    N[f]--;
    N[s]++;
    int sum2 = rec(i + 1);
    N[s]--;
    return max(sum1, sum2);
  };

  cin >> n >> m;
  for (int i = 0; i < m; ++i)
    cin >> M[i].first >> M[i].second;
  cin >> k;
  for (int i = 0; i < k; ++i)
    cin >> K[i].first >> K[i].second;
  cout << rec(0) << endl;
}

#include<bits/stdc++.h>
#define SORT(v) sort(v.rbegin() , v.rend())
#define si(n) scanf( "%d" , &n)
#define sii(n , m) scanf( "%d %d" , &n , &m)
#define sl(n) scanf( "%lld" , &n)
#define sll(n , m) scanf( "%lld %lld" , &n, &m)
#define ss(cad) scanf( "%s" , cad)
#define sz(x) (int)x.size()
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl
#define N_MAX 1000010
#define M 1000000007
#define EPS 1e-9

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pi> vp;

pi vec[110];
pi per[110];
bool has[110];

int main(){
	int n, m;
	sii(n, m);
	for(int i = 0; i < m; i++){
		sii(vec[i].fst, vec[i].scn);
	}
	int k;
	si(k);
	for(int i = 0; i < k; i++)
		sii(per[i].fst, per[i].scn);
	int ans = 0;
	for(int mask = 0; mask < (1<<k); mask++){
		memset(has, 0, sizeof(has));
		for(int i = 0; i < k; i++)
			if(mask&(1<<i))
				has[per[i].fst] = 1;
			else
				has[per[i].scn] = 1;
		int tmp = 0;
		for(int i = 0; i < m; i++)
			if(has[vec[i].fst] && has[vec[i].scn])
				tmp++;
		ans = max(ans, tmp);
	}
	printf("%d\n", ans);
  return 0;
}