#include <bits/stdc++.h>
using namespace std;
struct uni {
  int p[2222];
  uni() { fill(p, p + 2222, -1); }
  int root(int a) { return p[a] < 0 ? a : (p[a] = root(p[a])); }
  bool find(int a, int b) { return root(a) == root(b); }
  void merge(int a, int b) {
    if (!find(a, b)) p[root(a)] = root(b);
  }
};
bool chk[2222];
bool di[2222][2222];
int main(void) {
  int n, a, b;
  uni v, w;
  scanf("%d", &n);
  scanf("%d", &a);
  for (int i = 0; i < a; i++) {
    int f, t;
    scanf("%d%d", &f, &t);
    --f;
    --t;
    v.merge(f, t);
  }
  scanf("%d", &b);
  for (int i = 0; i < b; i++) {
    int f, t;
    scanf("%d%d", &f, &t);
    --f;
    --t;
    di[f][t] = di[t][f] = true;
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (chk[i]) continue;
    int p[2222], c;
    c = 0;
    for (int j = 0; j < n; j++) {
      if (v.find(i, j)) {
        if (chk[j]) return -1;
        p[c++] = j;
        chk[j] = true;
      }
    }
    if (res > c) continue;
    bool ok = true;
    for (int j = 0; ok && j < c; j++) {
      for (int k = j + 1; ok && k < c; k++) {
        if (di[p[j]][p[k]]) ok = false;
      }
    }
    if (ok) res = max(res, c);
  }
  printf("%d\n", res);
  return 0;
}
