#include <bits/stdc++.h>
using namespace std;
void dfs(long long &m, vector<bool> &dist,
         unordered_map<long long, vector<long long>> &adjlist,
         unordered_map<long long, vector<long long>> &dislike,
         vector<bool> &temp, long long y) {
  for (auto i : adjlist[y]) {
    if (!dist[i]) {
      dist[i] = true;
      temp[i] = true;
      m++;
      dfs(m, dist, adjlist, dislike, temp, i);
    }
  }
  for (auto i : dislike[y]) {
    if (temp[i]) {
      m = -1e9;
      break;
    }
  }
}
int main() {
  long long n, m;
  cin >> n >> m;
  unordered_map<long long, vector<long long>> adjlist, dislike;
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    adjlist[x].push_back(y);
    adjlist[y].push_back(x);
  }
  long long p;
  cin >> p;
  for (long long i = 0; i < p; i++) {
    long long x, y;
    cin >> x >> y;
    dislike[x].push_back(y);
    dislike[y].push_back(x);
  }
  long long ans(0), s(0);
  vector<bool> dist(n + 1, false);
  for (long long i = 1; i <= n; i++) {
    if (!dist[i]) {
      vector<bool> temp(n + 1, false);
      s = 1;
      dist[i] = true;
      dfs(s, dist, adjlist, dislike, temp, i);
      ans = max(ans, s);
    }
  }
  cout << ans << endl;
  return 0;
}
