#include <bits/stdc++.h>
using namespace std;
vector<long long> g[2002];
vector<bool> fr(2002);
long long dis = 0;
void dfs(long long x) {
  fr[x] = true;
  for (auto i : g[x]) {
    if (!fr[i]) ++dis, dfs(i);
  }
}
int32_t main() {
  long long n, k, m;
  cin >> n >> k;
  unordered_map<long long, long long> mp;
  for (long long i = 1; i <= n; ++i) fr[i] = false;
  while (k--) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b), g[b].push_back(a);
  }
  cin >> m;
  while (m--) {
    long long a, b;
    cin >> a >> b;
    mp[a] = b, mp[b] = a;
  }
  bool flag = false, check = false;
  long long c = 0, ans = 0;
  for (long long i = 1; i <= n; ++i) {
    dis = 0, c = 0;
    if (!fr[i]) {
      dfs(i);
      if (dis == 0) ans = max(ans, dis), check = true;
      if (ans < dis) {
        for (long long i = 1; i <= n; ++i) {
          if (fr[i] && mp[i] > 0 && fr[mp[i]]) {
            flag = true;
            break;
          }
        }
        if (!flag) ans = max(ans, dis), check = true;
      }
    }
    for (long long i = 1; i <= n; ++i) fr[i] = false;
  }
  if (check) ++ans;
  cout << ans << endl;
}
