#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;

class dstream : public ostream {};

template <typename T>
dstream &operator<<(dstream &os, T v) {
#ifdef ATCODERDEBUG
  cout << v;
#endif
  return os;
}

ostream &endd(std::ostream &out) {
#ifdef ATCODERDEBUG
  out << std::endl;
#endif
  return out;
}
dstream dout;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "[ ";
  for (auto const &x : v) {
    os << x;
    if (&x != &v.back()) {
      os << " : ";
    }
  }
  os << " ]" << endl;
  return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
  os << "[" << endl;
  for (auto const &x : v) {
    os << " ";
    print_vec(x);
  }
  os << "]" << endl;
  return os;
}

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
  if (comp(xmax, x)) {
    xmax = x;
    return true;
  }
  return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
  if (comp(x, xmin)) {
    xmin = x;
    return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll N, M, K, a, b, c, d;
  cin >> N >> M;
  vector<pair<ll, ll>> ablist;
  REP(i, M) {
    cin >> a >> b;
    a--;
    b--;
    ablist.push_back(make_pair(a, b));
  }
  cin >> K;
  vector<pair<ll, ll>> cdlist;
  REP(i, K) {
    cin >> c >> d;
    c--;
    d--;
    cdlist.push_back(make_pair(c, d));
  }

  ll ans = 0;
  for (unsigned long i = 0; i < pow(2LL, K); i++) {
    vector<ll> llist(N, 0);
    for (unsigned long j = 0; j < K; j++) {
      ll idx = 0;
      if ((i >> j) & 1)
        idx = cdlist[j].first;
      else
        idx = cdlist[j].second;

      llist[idx]++;
    }
    ll cnt = 0;
    REP(j, M) {
      if (llist[ablist[j].first] > 0 && llist[ablist[j].second] > 0) cnt++;
    }

    dout << cnt << " " << i << "" << llist << endd;
    chmax(ans, cnt);
  }

  // dout << ((2 >> 0) & 1) << endd;
  cout << ans << endl;
  // cout << std::fixed << std::setprecision(15) << sqrt(ans) << endl;
}
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>


using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

const long long int mod = 998244353;
const long long int INF = 1e16;
const long double PI=3.14159265358979323; 
const long long int pl=1100;
const long double eps =0.0000001;

long long int res=0,N,M,K,A[200200],B[200200],C[200200],D[200200],memo[200200]={};
int main()
{
    cout << fixed << setprecision(18);
    cin>>N>>M;
    for (long long int  i = 0; i < M; i++)
    {
        cin>>A[i]>>B[i];
        
    }
    cin>>K;
    for (long long int  i = 0; i < K; i++)
    {
        cin>>C[i]>>D[i];
        
    }
    for (long long int i = 0; i < (1<<K); i++)
    {
        for (long long int j = 0; j <= N; j++)
        {
            memo[j]=0;
        }
        
        for (long long int j = 0; j < K; j++)
        {
            if((i&(1<<j))==0){
                memo[C[j]]=1;
            }else{
                memo[D[j]]=1;
            }
        }
        long long int tmp=0;
        for (long long int j = 0; j < M; j++)
        {
            if(memo[A[j]]==1&&memo[B[j]]==1){
                tmp++;
            }
        }
        res=max(res,tmp);
    }
    cout<<res<<endl;
    
    
}
