#include <bits/stdc++.h>
using namespace std;
long long *id, cnt, *sz;
map<long long, long long> mp;
void init(long long N) {
  cnt = N;
  id = new long long[N + 1];
  sz = new long long[N + 1];
  for (long long i = 1; i <= N; i++) {
    id[i] = i;
    sz[i] = 1;
  }
}
long long find(long long p) {
  if (id[p] == p)
    return p;
  else {
    id[p] = find(id[p]);
    return id[p];
  }
}
void merge(long long x, long long y) {
  long long i = find(x);
  long long j = find(y);
  if (i == j) return;
  if (sz[i] < sz[j]) {
    id[i] = j;
    sz[j] += sz[i];
  } else {
    id[j] = i;
    sz[i] += sz[j];
  }
  cnt--;
}
bool connected(long long x, long long y) { return find(x) == find(y); }
long long count() { return cnt; }
void destroy() {
  delete[] id;
  delete[] sz;
}
long long s1[1000000], e[1000000], a[1000000], b[1000000];
bool visited[1000000];
bool temp[2009][2009];
int main() {
  long long n, k, i, m, x, y, res;
  set<long long> s;
  vector<vector<long long> > v;
  cin >> n;
  init(n);
  cin >> k;
  for (i = 1; i <= k; i++) {
    cin >> s1[i] >> e[i];
  }
  cin >> m;
  for (i = 1; i <= m; i++) {
    cin >> a[i] >> b[i];
    temp[a[i]][b[i]] = 1;
    temp[b[i]][a[i]] = 1;
  }
  for (i = 1; i <= k; i++) {
    x = s1[i];
    y = e[i];
    merge(x, y);
  }
  vector<long long> v2;
  for (i = 1; i <= n; i++) {
    v2.push_back(find(i));
  }
  v.resize(n + 1);
  for (i = 1; i <= n; i++) {
    v[find(i)].push_back(i);
  }
  res = -1;
  bool flag;
  for (long long k = 0; k < v2.size(); k++) {
    long long z = v2[k];
    flag = true;
    for (i = 0; (i < v[z].size()) && flag; i++) {
      for (long long j = i + 1; (j < v[z].size()) && flag; j++) {
        if (temp[v[z][i]][v[z][j]]) flag = false;
      }
    }
    if (flag) res = max(res, sz[z]);
  }
  if (res == -1)
    cout << 0;
  else
    cout << res;
  return 0;
}
