#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > G[2002];
int vis[2002];
void go(int i, int col) {
  vis[i] = col;
  for (int j = 0; j < G[i].size(); j++) {
    int v = G[i][j].first;
    int w = G[i][j].second;
    if (w == 1) {
      if (vis[v] != 3) go(v, col);
    }
  }
  return;
}
int flag = 0;
void dfs(int i, int col) {
  if (flag == 1) {
    return;
  }
  if (vis[i] == 3) {
    return;
  }
  if (vis[i] == 0) {
    vis[i] = col;
  } else {
    if (vis[i] != col) {
      go(i, 3);
      flag = 1;
      return;
    } else {
      return;
    }
  }
  if (col == 1) {
    for (int j = 0; j < G[i].size(); j++) {
      int v = G[i][j].first;
      int w = G[i][j].second;
      if (w == 1) {
        dfs(v, 1);
      } else {
        dfs(v, 2);
      }
    }
  } else {
    for (int j = 0; j < G[i].size(); j++) {
      int v = G[i][j].first;
      int w = G[i][j].second;
      if (w == 1) {
        dfs(v, 2);
      }
    }
  }
}
int main() {
  int n, k, m;
  cin >> n;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(make_pair(b, 1));
    G[b].push_back(make_pair(a, 1));
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(make_pair(b, 2));
    G[b].push_back(make_pair(a, 2));
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    flag = 0;
    if (vis[i] == 0) {
      dfs(i, 1);
      if (flag == 0) {
        int cnt = 0;
        for (int j = 1; j <= n; j++) {
          if (vis[j] == 1) {
            vis[j] = 3;
            cnt++;
          } else if (vis[j] == 2) {
            vis[j] = 0;
          }
        }
        mx = max(mx, cnt);
      }
    }
  }
  cout << mx << "\n";
  return 0;
}
