#include <bits/stdc++.h>
using namespace std;
int n, k, m;
vector<vector<int> > G;
vector<pair<int, vector<int> > > F;
vector<char> used;
int s = 0;
void dfs(int v, vector<int>& f) {
  used[v] = 1;
  f.push_back(v);
  for (int i = 1; i < n; i++)
    if (!used[i] && G[v][i] == 1) dfs(i, f);
}
void dfs1(int v) {
  vector<int> f;
  dfs(v, f);
  F.push_back(pair<int, vector<int> >(f.size(), f));
}
int main() {
  cin >> n;
  n++;
  G.assign(n, vector<int>(n, 0));
  used.assign(n, 0);
  cin >> k;
  for (int i = 0; i < k; i++) {
    int p, q;
    cin >> p >> q;
    G[p][q] = G[q][p] = 1;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int p, q;
    cin >> p >> q;
    G[p][q] = G[q][p] = 2;
  }
  for (int i = 1; i < n; i++) {
    if (!used[i]) dfs1(i);
  }
  sort(F.rbegin(), F.rend());
  bool fl = 1;
  int i;
  for (i = 0; i < F.size(); i++) {
    bool zf = 1;
    for (int j = 0; j < F[i].first - 1 && zf; j++)
      for (int kj = j + 1; kj < F[i].first; kj++)
        if (G[F[i].second[j]][F[i].second[kj]] == 2) {
          zf = 0;
          break;
        }
    if (zf) {
      fl = 0;
      break;
    }
  }
  if (fl) {
    cout << 0;
    return 0;
  }
  cout << F[i].first;
  return 0;
}
