#include <bits/stdc++.h>
const int MAXN = 2010;
int N;
int ar[MAXN][MAXN];
int used[MAXN];
int vis[MAXN];
int par;
int enemy[MAXN][MAXN];
void read() {
  int i, M, a, b;
  scanf(" %d %d", &N, &M);
  for (i = 1; i <= M; i++) {
    scanf(" %d %d", &a, &b);
    ar[a][b] = ar[b][a] = 1;
  }
  scanf(" %d", &M);
  for (i = 1; i <= M; i++) {
    scanf(" %d %d", &a, &b);
    enemy[a][b] = enemy[b][a] = 1;
  }
}
void dfs(int a) {
  vis[++par] = a;
  used[a] = 1;
  int i;
  for (i = 1; i <= N; i++)
    if (ar[a][i] && !used[i]) dfs(i);
}
bool control() {
  int i, j;
  for (i = 1; i <= par; i++)
    for (j = 1; j <= par; j++)
      if (enemy[vis[i]][vis[j]]) return false;
  return true;
}
int main() {
  read();
  int i, max = 0;
  for (i = 1; i <= N; i++)
    if (!used[i]) {
      par = 0;
      dfs(i);
      if (par > max && control()) max = par;
    }
  printf("%d\n", max);
  return 0;
}
