#include <bits/stdc++.h>
using namespace std;
int h[10000][3];
int parent(int x) {
  while (h[x][0] != x) x = h[x][0];
  return x;
}
void merge(int x, int y) {
  if (x == y) return;
  if (h[x][1] == h[y][1]) {
    h[y][0] = x;
    h[x][1]++;
    h[x][2] += h[y][2];
  } else if (h[x][1] > h[y][1]) {
    h[y][0] = x;
    h[x][2] += h[y][2];
  } else {
    h[x][0] = y;
    h[y][2] += h[x][2];
  }
}
int main() {
  int n;
  int k, m;
  cin >> n;
  int i, j;
  for (i = 1; i <= n; i++) {
    h[i][0] = i;
    h[i][1] = h[i][2] = 1;
  }
  cin >> k;
  int x, y;
  for (i = 0; i < k; i++) {
    cin >> x >> y;
    merge(parent(x), parent(y));
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    int p = parent(x), q = parent(y);
    if (p == q) h[p][2] = h[q][2] = -1;
  }
  int t = 0;
  h[0][2] = -1;
  for (i = 1; i <= n; i++) {
    if (h[parent(i)][2] > h[t][2]) t = i;
  }
  if (h[t][2] > 0)
    cout << h[t][2] << '\n';
  else
    cout << 0 << '\n';
  return 0;
}
