#include <bits/stdc++.h>
using namespace std;
bitset<2005> used, b;
vector<int> like[2005], dislike[2005];
int n;
int solve(int idx) {
  b.reset();
  queue<int> q;
  q.push(idx);
  b.set(idx);
  used.set(idx);
  int ans = 1;
  bool flag = false;
  while (!q.empty()) {
    int curr = q.front();
    q.pop();
    for (int i = 0; i < like[curr].size(); i++) {
      int u = like[curr][i];
      if (b.test(u)) continue;
      for (int j = 0; !flag && j < dislike[u].size(); j++) {
        int v = dislike[u][j];
        if (b.test(v)) flag = true;
      }
      q.push(u);
      b.set(u);
      used.set(u);
      ans++;
    }
  }
  if (flag) return 0;
  return ans;
}
int solve() {
  int ans = 0;
  used.reset();
  for (int i = 1; i <= n; i++) {
    if (used.test(i)) continue;
    ans = max(ans, solve(i));
  }
  return ans;
}
int main() {
  int k, m, u, v;
  scanf("%d", &n);
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &u, &v);
    like[u].push_back(v);
    like[v].push_back(u);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    dislike[u].push_back(v);
    dislike[v].push_back(u);
  }
  printf("%d\n", solve());
  return 0;
}
