#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e3 + 100;
long long n, m, k;
vector<long long> adj[MAXN], path;
bool vis[MAXN], Bad[MAXN][MAXN];
void dfs(long long x) {
  vis[x] = true;
  path.push_back(x);
  for (long long i = 0; i < adj[x].size(); i++) {
    if (!vis[adj[x][i]]) {
      dfs(adj[x][i]);
    }
  }
  return;
}
int check(long long x) {
  path.clear();
  dfs(x);
  for (long long i = 0; i < path.size(); i++)
    for (long long j = i + 1; j < path.size(); j++)
      if (Bad[path[i]][path[j]]) return 0;
  return path.size();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v), adj[v].push_back(u);
  }
  cin >> k;
  for (long long i = 0; i < k; i++) {
    long long u, v;
    cin >> u >> v;
    Bad[u][v] = true, Bad[v][u] = true;
  }
  int ans = -1;
  for (long long i = 1; i <= n; i++) {
    ans = max(ans, check(i));
    for (long long i = 1; i <= n; i++) vis[i] = false;
  }
  cout << ans;
}
