#include <bits/stdc++.h>
using namespace std;
vector<int> gr[2005];
bool hate[2005][2005];
bool vis[2005];
int cnt;
vector<int> cur;
void dfs(int src) {
  vis[src] = 1;
  cnt++;
  cur.push_back(src);
  for (auto nbr : gr[src]) {
    if (!vis[nbr]) dfs(nbr);
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < k; i++) {
    int u, v;
    cin >> u >> v;
    gr[u].push_back(v);
    gr[v].push_back(u);
  }
  int m;
  cin >> m;
  memset(hate, false, sizeof hate);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    hate[u][v] = hate[v][u] = 1;
  }
  int ans = 0;
  memset(vis, false, sizeof vis);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      cnt = 0;
      dfs(i);
      bool flag = 1;
      for (int j = 0; j < cur.size(); j++) {
        for (int k = j + 1; k < cur.size(); k++) {
          if (hate[cur[j]][cur[k]]) {
            flag = 0;
            break;
          }
        }
        if (!flag) break;
      }
      if (flag) ans = max(ans, cnt);
      cur.clear();
    }
  }
  cout << ans;
  return 0;
}
