#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
vector<int> edge[maxn];
int st[maxn], dfn[maxn], low[maxn];
int Top, Btype, Time;
int Belong[maxn], n, m;
bool ins[maxn];
void tarjan(int s) {
  int i, t;
  dfn[s] = low[s] = ++Time;
  ins[s] = true;
  st[++Top] = s;
  for (i = 0; i < edge[s].size(); i++) {
    t = edge[s][i];
    if (!dfn[t]) {
      tarjan(t);
      if (low[t] < low[s]) low[s] = low[t];
    } else if (ins[t] && dfn[t] < low[s])
      low[s] = dfn[t];
  }
  if (dfn[s] == low[s]) {
    Btype++;
    do {
      t = st[Top--];
      ins[t] = false;
      Belong[t] = Btype;
    } while (t != s);
  }
}
void SCC(int n) {
  int i;
  Top = Btype = Time = 0;
  memset(ins, 0, sizeof(ins));
  memset(dfn, 0, sizeof(dfn));
  for (i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  return;
}
int chu[maxn], cnt[maxn];
bool mark[maxn];
int main() {
  int i, a, b;
  while (scanf("%d", &n) != -1) {
    scanf("%d", &m);
    for (i = 1; i <= n; i++) edge[i].clear();
    for (i = 0; i < m; i++) {
      scanf("%d%d", &a, &b);
      edge[a].push_back(b);
      edge[b].push_back(a);
    }
    SCC(n);
    memset(mark, false, sizeof(mark));
    scanf("%d", &m);
    for (i = 0; i < m; i++) {
      scanf("%d%d", &a, &b);
      if (Belong[a] == Belong[b]) mark[Belong[a]] = 1;
    }
    int ans[maxn], Max = 0;
    memset(ans, 0, sizeof(ans));
    for (i = 1; i <= n; i++) {
      if (!mark[Belong[i]]) ans[Belong[i]]++;
      Max = Max < ans[Belong[i]] ? ans[Belong[i]] : Max;
    }
    printf("%d\n", Max);
  }
  return 0;
}
