#include <bits/stdc++.h>
using namespace std;
int q(vector<vector<int> >& a, vector<int>& s, vector<int>& v, int i) {
  int an = 1;
  s.push_back(i);
  v[i] = 1;
  for (int j = 0; j < a[i].size(); j++)
    if (v[a[i][j]] == 0) an += q(a, s, v, a[i][j]);
  return an;
}
int main() {
  int n, f, d;
  cin >> n >> f;
  vector<vector<int> > a(n);
  for (int i = 0; i < f; i++) {
    int s, e;
    cin >> s >> e;
    a[s - 1].push_back(e - 1);
    a[e - 1].push_back(s - 1);
  }
  cin >> d;
  vector<vector<int> > e(n, vector<int>(n));
  for (int i = 0; i < d; i++) {
    int s, ed;
    cin >> s >> ed;
    e[s - 1][ed - 1] = e[ed - 1][s - 1] = 1;
  }
  vector<int> v(n);
  int an = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == 1) continue;
    vector<int> s;
    int t = q(a, s, v, i), fl = 0;
    for (int j = 0; j < t; j++) {
      for (int k = j + 1; k < t; k++) {
        if (e[s[j]][s[k]]) {
          fl = 1;
          break;
        }
      }
      if (fl) break;
    }
    if (fl == 0) an = max(an, t);
  }
  cout << an << endl;
  return 0;
}
