#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[3000];
bool ma[3000][3000] = {};
bool vis[3000] = {};
set<long long> like, dislike;
bool val;
void pri(set<long long> s) {
  set<long long>::iterator it;
  for (it = s.begin(); it != s.end(); it++) cout << *it << " ";
  cout << endl;
}
void init(long long n) {
  like.clear();
  like.insert(n);
  dislike.clear();
  val = true;
}
void dfs(long long n) {
  vis[n] = true;
  for (long long i = 0; i < adj[n].size(); i++) {
    long long u = adj[n][i];
    if (!ma[n][u]) {
      if (like.find(u) != like.end()) val = false;
      dislike.insert(u);
    } else {
      if (dislike.find(u) != dislike.end()) val = false;
      like.insert(u);
      if (!vis[u]) dfs(u);
    }
  }
}
int main() {
  long long n;
  cin >> n;
  long long k;
  cin >> k;
  pair<long long, long long> a[k];
  for (long long i = 0; i < k; i++) {
    long long c, d;
    cin >> c >> d;
    a[i].first = c;
    a[i].second = d;
    adj[c].push_back(d);
    adj[d].push_back(c);
    ma[c][d] = ma[d][c] = true;
  }
  long long m;
  cin >> m;
  pair<long long, long long> b[m];
  for (long long i = 0; i < m; i++) {
    long long c, d;
    cin >> c >> d;
    b[i].first = c;
    b[i].second = d;
    adj[c].push_back(d);
    adj[d].push_back(c);
  }
  long long res = 0;
  for (long long i = 1; i <= n; i++) {
    init(i);
    if (!vis[i]) {
      dfs(i);
      long long tam = like.size();
      if (val) res = max(res, tam);
    }
  }
  cout << res << endl;
  return 0;
}
