#include <bits/stdc++.h>
using namespace std;

const long long int mod = 1000000007;
const long long int big = 2999999999999999999;
const long long int small = -2999999999999999999;
#define ll long long int 
#define pb(a) push_back(a)
#define vll vector<long long int>
#define loop(i, n) for(long long int i=1;i<=n;i++)
#define loop0(i, n) for(long long int i=0;i<n;i++)
#define in(i) scanf("%lld", &i);
#define out(i) printf("%lld", i)
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>

ll n, m, k;
vll a, b, c, d;

void in2(ll& a, ll& b)
{
  in(a);
  in(b);
}
void in3(ll& a, ll& b, ll& c)
{
  in(a);
  in(b);
  in(c);
}

ll howMany(vll counter)
{
  ll ret = 0;
  loop0(i, m)
  {
    if(counter[a[i]] && counter[b[i]])
      ret += 1;
  }
  return ret;
}

ll solve(ll i, vll occ)
{
  if(i == k-1)
  {
    return howMany(occ);
  }
  occ[c[i+1]] += 1;
  ll a = solve(i+1, occ);
  occ[c[i+1]] -= 1;
  occ[d[i+1]] += 1;
  ll b = solve(i+1, occ);
  occ[d[i+1]] -= 1;
  return max(a, b);
}

int main()
{
  in2(n, m);
  a.resize(m);
  b.resize(m);
  loop0(i, m)
  {
    in2(a[i], b[i]);
  }
  in(k);
  c.resize(k);
  d.resize(k);
  loop0(i, k)
  {
    in2(c[i], d[i]);
  }
  vll occ(n+1, 0);
  ll ans = solve(-1, occ);
  cout<<ans<<"\n";
}


//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

LL gcd(LL a, LL b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int ri(){
    int n;
    scanf("%d",&n);
    return n;
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> cond(M);
    for (auto &[A, B] : cond)
        cin >> A >> B;
    int K;
    cin >> K;
    vector<pair<int, int>> choice(K);
    for (auto &[C, D] : choice)
        cin >> C >> D;

    int ans = 0;
    for (int bit = 0; bit < 1 << K; bit++)
    {
        vector<bool> ball(N);
        for (int i = 0; i < K; i++)
        {
            const auto [C, D] = choice[i];
            ball[bit & 1 << i ? C : D] = 1;
        }
        int cnt = 0;
        for (auto [A, B] : cond)
            if (ball[A] && ball[B])
                cnt++;
        if (ans < cnt)
            ans = cnt;
    }
    cout << ans << endl;
}