#include <bits/stdc++.h>
std::vector<std::vector<unsigned>*> parties;
std::list<std::vector<unsigned>> groups;
class Pair {
 public:
  unsigned m_first;
  unsigned m_second;
  Pair() : m_first(0), m_second(0) {}
  void read(bool is_a_friends) {
    std::cin >> m_first >> m_second;
    m_first--;
    m_second--;
    if (is_a_friends && parties[m_first] != parties[m_second]) {
      parties[m_first]->insert(parties[m_first]->end(),
                               parties[m_second]->begin(),
                               parties[m_second]->end());
      std::vector<unsigned>* ptr = parties[m_second];
      for (auto i = ptr->begin(), end = ptr->end(); i != end; ++i)
        parties[*i] = parties[m_first];
      ptr->clear();
    } else if (!is_a_friends && parties[m_first] == parties[m_second])
      parties[m_first]->clear();
  }
};
void read(bool is_a_friends) {
  unsigned k(0);
  Pair pair;
  std::cin >> k;
  for (unsigned i = 0; i < k; i++) pair.read(is_a_friends);
}
int main() {
  unsigned size(0);
  std::cin >> size;
  parties.assign(size, nullptr);
  for (unsigned i = 0; i < size; i++) {
    groups.push_front(std::vector<unsigned>(1, i));
    parties[i] = &groups.front();
    parties[i]->reserve(size);
  }
  read(true);
  read(false);
  unsigned max(0);
  for (auto i = groups.begin(); i != groups.end(); ++i)
    if (max < i->size()) max = i->size();
  std::cout << max;
  return 0;
}
