#include <bits/stdc++.h>
using namespace std;
long long dfs(long long i, vector<vector<long long>> &v,
              vector<vector<long long>> &v1, vector<long long> &isit,
              vector<long long> &temp) {
  if (isit[i] != 0) {
    return 0;
  }
  isit[i]++;
  temp[i]++;
  bool flag = 0;
  long long t = 1;
  for (long long j = 0; j < v[i].size(); j++) {
    if (isit[v[i][j]] == 0) {
      long long k = dfs(v[i][j], v, v1, isit, temp);
      if (k == -1) {
        flag = 1;
      }
      t += k;
    }
  }
  for (long long j = 0; j < v1[i].size(); j++) {
    if (temp[v1[i][j]] == 1) {
      return -1;
    }
  }
  if (flag == 1) {
    return -1;
  } else {
    return t;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long l;
  long long dl;
  cin >> l;
  vector<vector<long long>> like(n + 1);
  for (long long i = 0; i < l; i++) {
    long long a, b;
    cin >> a >> b;
    like[a].push_back(b);
    like[b].push_back(a);
  }
  cin >> dl;
  vector<vector<long long>> dlike(n + 1);
  for (long long i = 0; i < dl; i++) {
    long long a, b;
    cin >> a >> b;
    dlike[a].push_back(b);
    dlike[b].push_back(a);
  }
  vector<long long> ans;
  long long ians = 0;
  vector<long long> isit(n + 1);
  for (long long i = 1; i <= n; i++) {
    if (isit[i] == 0) {
      vector<long long> temp(n + 1);
      long long t = dfs(i, like, dlike, isit, temp);
      ans.push_back(t);
    }
  }
  for (long long i : ans) {
    ians = max(ians, i);
  }
  cout << ians;
}
