#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > f;
vector<vector<int> > d;
vector<int> ch;
inline int dfs(int v) {
  ch[v] = 1;
  for (int i = 0; i < (int)d[v].size(); i++)
    if (ch[d[v][i]] == 1) return 0;
  int ret = 1;
  for (int i = 0; i < (int)f[v].size(); i++) {
    if (ch[f[v][i]] == -1) return -1;
    if (ch[f[v][i]] == 0) {
      int newr = dfs(f[v][i]);
      if (newr == 0) return 0;
      if (newr == -1) return -1;
      ret += newr;
    }
  }
  return ret;
}
int main() {
  ch.clear();
  f.clear();
  d.clear();
  int n, k, m;
  cin >> n;
  cin >> k;
  ch.resize(n, 0);
  f.resize(n);
  d.resize(n);
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    f[a - 1].push_back(b - 1);
    f[b - 1].push_back(a - 1);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    d[a - 1].push_back(b - 1);
    d[b - 1].push_back(a - 1);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int ne = dfs(i);
    ans = max(ans, ne);
    ch[i] = -1;
  }
  cout << ans << endl;
  return 0;
}
