#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000;
vector<int> good[maxn];
vector<int> bad[maxn];
int colorg[maxn], colorb[maxn];
int n, k, m;
int mg = 1, mb = 1;
void dfsg(int v, int c) {
  colorg[v] = c;
  for (int i = 0; i < (int)(good[v].size()); i++)
    if (!colorg[good[v][i]]) dfsg(good[v][i], c);
}
set<int> bbad[maxn];
void dfsb(int v, int c) {
  colorb[v] = c;
  for (int i = 0; i < (int)(bad[v].size()); i++)
    if (!colorb[bad[v][i]]) dfsb(bad[v][i], c);
}
vector<int> colors[maxn];
int main(void) {
  scanf("%d", &n);
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    int u, v;
    scanf("%d %d", &u, &v), --u, --v;
    good[u].push_back(v), good[v].push_back(u);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v), --u, --v;
    bad[u].push_back(v), bad[v].push_back(u);
    bbad[u].insert(v), bbad[v].insert(u);
  }
  for (int i = 0; i < n; i++) {
    if (!colorg[i]) dfsg(i, mg), mg++;
    if (!colorb[i]) dfsb(i, mb), mb++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) colors[colorg[i]].push_back(i);
  for (int i = 1; i < n; i++) {
    bool flag = true;
    for (int j = 0; j < (int)(colors[i].size()); j++)
      for (int k = j + 1; k < (int)(colors[i].size()); k++) {
        int u = colors[i][j], v = colors[i][k];
        if (bbad[u].find(v) != bbad[u].end()) flag = false;
      }
    if (flag) ans = max(ans, (int)colors[i].size());
  }
  cout << ans << endl;
  return 0;
}
