#include <bits/stdc++.h>
using namespace std;
using ll = long long;//大きなint型
using ld = long double;//大きなdouble型
using P = pair<int,int>;//pair型の型エイリアス
#define rep(i,n) for (int i = 0; i < (n); ++i)//iをnまですすめる。
#define PI 3.14159265359



int main(){
    int n,m;
    int ans = 0;
    int last_ans = 0;
    cin>>n>>m;
    int sara[n+1] = {0};
    vector<int> a(m),b(m);
    rep(i,m) cin>>a.at(i)>>b.at(i);
    int k;
    cin>>k;
    vector<int> c(k),d(k);
    rep(i,k) cin>>c.at(i)>>d.at(i);

    //bit全探索
    for(int bit = 0;bit < (1 << k); ++bit){
        rep(i,n+1) sara[i]=0;
        ans = 0;
        rep(i,k){
            if(bit & (1<<i)){//True
                sara[d.at(i)] = 1;
            }
            else sara[c.at(i)] = 1;
        }
        rep(i,m){
            //条件確認
            if(sara[a.at(i)] == 1 && sara[b.at(i)] == 1) ans++;
        }
        last_ans = max(ans,last_ans);//達成した条件数が大きいほうを保存

    }
    cout << last_ans;
    
}
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 110;
int a[MAXN], b[MAXN];
int ball[MAXN];
int c[20], d[20];
int n, m, k;
int ans = 0;
void dfs(int x) {
    if (x > k) {
        int cnt = 0;
//        for (int i = 1; i <= n; i++) {
//            cout << ball[i] << " ";
//        }
//        cout << endl;
        for (int i = 1; i <= m; i++) {
            if (ball[a[i]] && ball[b[i]]) {
                //cout << c[i] << " " << d[i] << endl;
                cnt++;
            }
        }
        //cout << "cnt:" << cnt << endl;
        ans = max(ans, cnt);
        return;
    }
    ball[c[x]]++;
    dfs(x + 1);
    ball[c[x]]--;
    ball[d[x]]++;
    dfs(x + 1);
    ball[d[x]]--;
}
int main() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> a[i] >> b[i];
    }
    cin >> k;
    for (int i = 1; i <= k; i++) {
        cin >> c[i] >> d[i];
    }
    dfs(1);
    cout << ans;
    return 0;
}