#include <bits/stdc++.h>
using namespace std;
const int oo = 1 << 20;
const double PI = M_PI;
const double EPS = 1e-15;
const int MaxN = 3001;
int N, A, B;
vector<int> G[MaxN];
bool M[MaxN][MaxN];
bool visited[MaxN];
int comp[MaxN], size;
void dfs(int u) {
  comp[size++] = u;
  visited[u] = true;
  for (int i = (int)G[u].size() - 1; i >= 0; i--) {
    int w = G[u][i];
    if (!visited[w]) dfs(w);
  }
}
int main() {
  cin.sync_with_stdio(false);
  cin >> N;
  cin >> A;
  for (int i = 0; i < (A); i++) {
    int u, v;
    cin >> u >> v;
    G[u - 1].push_back(v - 1);
    G[v - 1].push_back(u - 1);
  }
  cin >> B;
  for (int i = 0; i < (B); i++) {
    int u, v;
    cin >> u >> v;
    M[u - 1][v - 1] = true;
    M[v - 1][u - 1] = true;
  }
  int answer = 0;
  for (int i = 0; i < (N); i++)
    if (!visited[i]) {
      size = 0;
      dfs(i);
      bool valid = true;
      for (int j = 0; j < (size); j++) {
        for (int k = 0; k < (j); k++)
          if (M[comp[j]][comp[k]]) {
            valid = false;
            break;
          }
        if (!valid) break;
      }
      if (valid) answer = max(answer, size);
    }
  cout << answer << endl;
  return 0;
}
