#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int mod = 1000000007;
int N, M;
vector<int> g[2001];
vector<int> cur;
vector<bool> vis(2001);
int Gbad[2001][2001];
int ans;
void dfs(int v) {
  cur.push_back(v);
  vis[v] = true;
  for (int x : g[v])
    if (!vis[x]) dfs(x);
}
void check(vector<int> &v) {
  bool good = true;
  int N = v.size();
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++)
      if (Gbad[cur[j]][cur[i]] == 1) {
        good = false;
        break;
      }
  }
  int cur = v.size();
  if (good) ans = max(ans, cur);
}
void slv() {
  cin >> N >> M;
  int x, y;
  for (int i = 1; i <= M; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  int K;
  cin >> K;
  for (int i = 1; i <= K; i++) {
    cin >> x >> y;
    Gbad[x][y] = Gbad[y][x] = 1;
  }
  for (int i = 1; i <= N; i++) {
    if (vis[i] == 0) {
      dfs(i);
      check(cur);
      cur.clear();
    }
  }
  cout << ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  while (T--) slv();
  return 0;
}
