#include <bits/stdc++.h>
using namespace std;
int m, n, t, q, r, w, a, b;
int p[3000], cnt[3000] = {0};
bool ok[3000];
int find(int x) { return x == p[x] ? x : (p[x] = find(p[x])); }
void uni(int x, int y) { p[find(x)] = find(y); }
bool eqi(int x, int y) { return find(x) == find(y); }
int main() {
  for (int i = 0; i < 3000; i++) {
    ok[i] = 1;
    p[i] = i;
  }
  scanf("%d", &t);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    uni(a, b);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    if (eqi(a, b)) {
      ok[find(a)] = 0;
    }
  }
  for (int i = 1; i <= t; i++) {
    if (ok[find(i)]) cnt[find(i)]++;
  }
  int ret = 0;
  for (int i = 1; i <= t; i++)
    if (cnt[i] > ret) ret = cnt[i];
  printf("%d\n", ret);
  return 0;
}
