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

using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

const ll MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    REP(i, M) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    int K;
    cin >> K;
    vector<int> C(K), D(K);
    REP(i, K) {
        cin >> C[i] >> D[i];
        C[i]--;
        D[i]--;
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << K); bit++) {
        vector<int> cnt(N);
        REP(i, K) {
            if (bit & (1 << i))
                cnt[C[i]]++;
            else
                cnt[D[i]]++;
        }
        int s = 0;
        REP(i, M) {
            if (cnt[A[i]] >= 1 && cnt[B[i]] >= 1)
                s++;
        }
        chmax(ans, s);
    }
    cout << ans << endl;
}
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <limits.h>
#include <stdio.h>
using namespace std;
 
int main()
{
    int n,m;
    cin >> n >> m; 
    int a[m], b[m];
    std::vector<int> v;
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i];
    }
    int k;
    cin >> k;
    int c[k], d[k];
    
    for(int i=0; i<k; i++){
        cin >> c[i] >> d[i];
    }
    
    long long int ans = 0;
    for(long long int i=0; i<pow(2.0, k); i++){
        std::map<int, int> mp;
        std::bitset<16> bs(i);
        for(long long int j=0; j<k; j++){
            if(bs[j]==0){
                mp[c[j]]++;
            }else{
                mp[d[j]]++;
            }
        }
        long long int cnt = 0;
        for(long long int j=0; j<m; j++){
            if(mp[a[j]]>0 && mp[b[j]]>0){
                cnt++;
            }
        }
        if(ans < cnt) ans = cnt;
    }
    cout << ans << endl;
    
    return 0;
}