#include <bits/stdc++.h>
using namespace std;
long long n;
vector<vector<long long> > g, ga;
vector<long long> used, comp, used2;
long long dfs(long long v) {
  used[v] = 1;
  comp.push_back(v);
  for (long long i = 0; i < n; i++) {
    if (ga[v][i]) {
      if (used[i] == 1) {
        comp.clear();
        return 1;
      }
    } else {
      if (g[v][i] and !used[i]) {
        if (dfs(i)) {
          return 1;
        }
      }
    }
  }
  return 0;
}
signed main() {
  cin >> n;
  g.resize(n, vector<long long>(n, 0));
  used.resize(n), ga.resize(n, vector<long long>(n, 0));
  long long k;
  cin >> k;
  for (long long i = 0; i < k; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a][b] = 1;
    g[b][a] = 1;
  }
  cin >> k;
  for (long long i = 0; i < k; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    ga[a][b] = 1;
    ga[b][a] = 1;
  }
  vector<long long> ans;
  for (long long i = 0; i < n; i++) {
    if (!used[i]) {
      comp.clear();
      used.clear();
      used.resize(n);
      dfs(i);
      if (comp.size() >= ans.size()) {
        ans = comp;
      }
    }
  }
  cout << ans.size() << '\n';
}
