#include <bits/stdc++.h>
using namespace std;
const int mxn = 2000 + 10;
vector<int> v[mxn];
vector<pair<int, int> > v2;
int n, m;
int mx;
bool viz[mxn];
int dfs(int nod) {
  int nr = 0;
  stack<int> s;
  s.push(nod);
  viz[nod] = 1;
  int nx;
  while (!s.empty()) {
    nx = s.top();
    s.pop();
    nr++;
    for (auto it : v[nx])
      if (viz[it] == 0) {
        s.push(it);
        viz[it] = 1;
      }
  }
  bool ok = 1;
  for (int i = 0; i < v2.size(); i++) {
    if (viz[v2[i].first] && viz[v2[i].second]) {
      ok = 0;
      v2.erase(v2.begin() + i);
    }
  }
  if (nr == 1) return 1;
  return nr * ok;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1, xx, yy; i <= m; i++) {
    cin >> xx >> yy;
    v[xx].push_back(yy);
    v[yy].push_back(xx);
  }
  cin >> m;
  for (int i = 1, xx, yy; i <= m; i++) {
    cin >> xx >> yy;
    v2.push_back(make_pair(xx, yy));
  }
  sort(v2.begin(), v2.end(), less<pair<int, int> >());
  for (int i = 1; i <= n; i++)
    if (viz[i] == 0) mx = max(mx, dfs(i));
  cout << mx;
  return 0;
}
