#include <bits/stdc++.h>
using namespace std;
struct Node {
  int gid, v;
};
vector<int> fr[2003];
int root[2003], n;
bool hate[2003][2003];
Node node[2003];
bool cmp(const Node &a, const Node &b) { return a.gid < b.gid; }
int find(int x) {
  if (x != root[x]) root[x] = find(root[x]);
  return root[x];
}
bool check(int s, int e) {
  int i, j;
  for (i = s; i < e; ++i) {
    for (j = i + 1; j < e; ++j) {
      if (hate[node[i].v][node[j].v]) return 0;
    }
  }
  return 1;
}
int main(int argc, char *argv[]) {
  int i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) root[i] = i;
  int k, u, v, m;
  scanf("%d", &k);
  for (i = 0; i < k; ++i) {
    scanf("%d%d", &u, &v);
    root[find(u)] = find(v);
  }
  for (i = 1; i <= n; ++i) {
    node[i].gid = find(i);
    node[i].v = i;
  }
  sort(node + 1, node + n + 1, cmp);
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= n; ++j) hate[i][j] = 0;
  }
  scanf("%d", &m);
  for (i = 0; i < m; ++i) {
    scanf("%d%d", &u, &v);
    hate[u][v] = 1;
    hate[v][u] = 1;
  }
  int ma = 0;
  for (j = 1, i = 2; i <= n; ++i) {
    if (node[i].gid != node[j].gid) {
      if (check(j, i)) {
        if (ma < (i - j)) ma = i - j;
      }
      j = i;
    }
  }
  if (check(j, i)) {
    if (ma < (i - j)) ma = i - j;
  }
  printf("%d\n", ma);
  return 0;
}
