#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > gr;
vector<int> v, f;
int dfs(int n) {
  int i, j, k;
  v[n] = 1;
  f[n] = 1;
  int ret = 1;
  for (i = 0; i < gr[n].size(); i++) {
    if (v[gr[n][i].first]) {
      if (gr[n][i].second == 2) return -1;
    } else {
      if (gr[n][i].second == 1) {
        k = dfs(gr[n][i].first);
        if (k == -1)
          return -1;
        else
          ret += k;
      }
    }
  }
  return ret;
}
int main() {
  int n, i, j, k, m;
  cin >> n;
  gr.resize(n + 1);
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    gr[j].push_back(make_pair(k, 1));
    gr[k].push_back(make_pair(j, 1));
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    gr[j].push_back(make_pair(k, 2));
    gr[k].push_back(make_pair(j, 2));
  }
  int ans = 0;
  v.resize(n + 1);
  f.resize(n + 1);
  for (i = 1; i <= n; i++) f[i] = 0;
  for (i = 1; i <= n; i++) {
    if (!f[i]) {
      for (j = 1; j <= n; j++) v[j] = 0;
      ans = max(ans, dfs(i));
    }
  }
  cout << ans << endl;
  return 0;
}
