#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, a[100001], b[100001], visit[2001], t;
set<int> gr, fin;
vector<long long> v[2001];
void dfs(int x) {
  visit[x] = 1;
  gr.insert(x);
  for (int i = 0; i < v[x].size(); i++)
    if (!visit[v[x][i]]) dfs(v[x][i]);
}
int main() {
  scanf("%d", &n);
  scanf("%d", &t);
  for (int i = 0; i < t; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) scanf("%d%d", &a[i], &b[i]);
  for (int i = 1; i <= n; i++) {
    gr.clear();
    if (!visit[i]) {
      dfs(i);
      for (int i = 0; i < m; i++) {
        if (gr.find(a[i]) != gr.end() && gr.find(b[i]) != gr.end()) {
          gr.clear();
          break;
        }
      }
      for (auto i = gr.begin(); i != gr.end(); i++) {
        if (i == prev(gr.end())) continue;
        set<int>::iterator p = i;
        p++;
        if ((*i) + 1 != *p) {
          gr.clear();
          break;
        }
      }
      fin.insert(gr.size());
    }
  }
  if (fin.empty())
    printf("0");
  else {
    set<int>::iterator i = prev(fin.end());
    printf("%d", *i);
  }
}
