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

#define REP(i,a,b) for(int i=a;i<=b;i++)
using LL = long long;

const int Nmax=2e5+9;
int N,M,A[109],B[109],C[19],D[19],K,ans,Ball[109],tmp;

int main() {
    ios_base::sync_with_stdio(0);    cin.tie(0);
    cin>>N>>M;
    REP(i,1,M) cin>>A[i]>>B[i];
    cin>>K;
    REP(i,1,K) cin>>C[i]>>D[i];
    REP(j,0,(1<<K)-1) {
        fill(Ball+1,Ball+N+1,0);
        REP(k,1,K) {
            if ((j>>(k-1))&1) Ball[C[k]]=1;
            else Ball[D[k]]=1;
        }
        tmp=0;
        REP(i,1,M) {
            if (Ball[A[i]] && Ball[B[i]]) ++tmp;
        }
        ans=max(ans,tmp);
    }
    cout<<ans;
    return 0;
}

#include<bits/stdc++.h>
using namespace  std;
 
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define ll           long long  
#define int          long long
#define vi           std::vector<int>
#define setbits(x)   __builtin_popcountll(x)
#define pb           push_back
#define fn           for(int i=0;i<n;i++)
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define all(x)       x.begin(), x.end()
#define  ret(x) {cout << #x << endl; return;}
#define PI           3.14159265358979323846
#define pii          pair<ll,ll>
#define fr           first
#define sc           second

const int mod = 1e+7;
void getio();
ll ceill(ll a, ll b) { return (a + b - 1) / b; }

ll fastpow(ll x, ll n)
{
    if (n == 0)
        return 1;
    ll res = 1;
    while (n)
    {
        if (n % 2)
            res = res * x;
        x = x * x;
        n = n >> 1;
    }
    return res;
}

// Function to generate all binary strings 
vector<vector<int>> store;
void generateAllBinaryStrings(int n, vi &arr, int i) 
{ 
    if (i == n) { 
        // printTheArray(arr, n); 
        store.pb(arr);
        return; 
    } 
  
    // First assign "0" at ith position 
    // and try for all other permutations 
    // for remaining positions 
    arr[i] = 0; 
    generateAllBinaryStrings(n, arr, i + 1); 
  
    // And then assign "1" at ith position 
    // and try for all other permutations 
    // for remaining positions 
    arr[i] = 1; 
    generateAllBinaryStrings(n, arr, i + 1); 
}

void solve()
{ 
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> use, chos;
    vector<pair<int, int>> ar;
    rep(i,0,m)
    {
        int a, b;
        cin >> a >> b;
        ar.push_back({a, b});
    }

    int k;
    cin >> k; 
    rep(i,0,k)
    {
        int c, d;
        cin >> c >> d;
        chos.pb({c, d});
    }

    vi per(k);
    generateAllBinaryStrings(k, per, 0);
    // cout << store.size();
    int ans = 0;
    int cnt = 0;
    for(int i=0; i<store.size(); i++)
    {
        cnt=0;
        vector<int> tem(n+1,0);
        for(int j=0; j<k; j++)
        {
            if(store[i][j] == 0)
                tem[chos[j].first]++;
            else tem[chos[j].second]++;
        }
        for(int i=0; i<m; i++)
        {
            if(tem[ar[i].first]>=1 and tem[ar[i].second]>=1)
                {
                    // cout << ar[i].first << ' ' << ar[i].second << endl;
                    cnt++;
                }
        }
        ans = max(ans, cnt);
    } 
    cout << ans << endl;
}


int32_t main()
{   
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    getio();
    // int t; cin >> t; while (t--)
    solve();
}
 
void getio()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}