#include <bits/stdc++.h>
using namespace std;
const double eps = 1E-9;
vector<int> used;
int ccolor = 1;
long long dfs(int u, vector<vector<int>>& g) {
  long long ans = 0;
  used[u] = ccolor;
  for (int i = 1; i < g[u].size(); ++i) {
    if (g[u][i] == -1 && used[i] == ccolor)
      return 0;
    else if (used[i] != ccolor && g[u][i] == 1) {
      long long k = dfs(i, g);
      if (k == 0) return 0;
      ans += k;
    }
  }
  return ans + 1;
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  used.resize(n + 1);
  vector<vector<int>> v(n + 1, vector<int>(n + 1));
  for (int i = 0; i < k; ++i) {
    int u, w;
    cin >> u >> w;
    v[u][w] = 1;
    v[w][u] = 1;
  }
  cin >> k;
  for (int i = 0; i < k; ++i) {
    int u, w;
    cin >> u >> w;
    v[u][w] = -1;
    v[w][u] = -1;
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = std::max(ans, dfs(i, v));
    ++ccolor;
  }
  cout << ans << endl;
  return 0;
}
