#include <bits/stdc++.h>
using namespace std;
void fast_io() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
const long long SIZE = (long long)2e3 + 10;
const int MOD = (long long)1e9;
vector<int> adj[SIZE + 10];
vector<int> anti[SIZE + 10];
int vis[SIZE + 10] = {0};
pair<int, bool> dfs(int u, int color) {
  vis[u] = color;
  bool valid = true;
  int cnt = 1;
  for (int i = 0; i < adj[u].size(); ++i) {
    int v = adj[u][i];
    if (vis[v] == 0) {
      pair<int, bool> ret = dfs(v, color);
      valid = valid && ret.second;
      cnt += ret.first;
    }
  }
  if (!valid) return make_pair(cnt, valid);
  for (int i = 0; i < anti[u].size(); ++i) {
    int v = anti[u][i];
    if (vis[v] == color) return make_pair(cnt, false);
  }
  return make_pair(cnt, true);
}
int main() {
  int n;
  scanf("%d", &n);
  int k;
  scanf("%d", &k);
  for (long long i = 0; i <= k - 1; i++) {
    int u, v;
    scanf("%d", &u);
    scanf("%d", &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  int m;
  scanf("%d", &m);
  for (long long i = 0; i <= m - 1; i++) {
    int u, v;
    scanf("%d", &u);
    scanf("%d", &v);
    anti[u].push_back(v);
    anti[v].push_back(u);
  }
  int mx = 0;
  for (long long i = 1; i <= n; i++)
    if (vis[i] == 0) {
      pair<int, bool> ret = dfs(i, i);
      if (ret.second) mx = max(ret.first, mx);
    }
  cout << mx;
  return 0;
}
