#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long int 
#define Sort(a) sort(a.begin(),a.end())
#define FOR(i,a) for(int i=0;i<a;i++)
#define print(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define scan(arr,n) for(int i=0;i<n;i++)cin>>arr[i]
#define MOD(x) x%1000000007
#define MAX 1e9
#define MIN -1e9
#define ff first
#define ss second
#define vi vector<int>
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define mem(x,val) memset((x),(val),sizeof(x))
#define sqr(x) x*x
#define sp <<" "
#define nl cout<<"\n"
#define pii pair<int,int>
#define startTime clock_t start, end; start = clock();
#define endTime end = clock(); double time_taken = double(end - start) / double(CLOCKS_PER_SEC); cout << "Time taken by program is : " << fixed  << time_taken << setprecision(5);cout << " sec " << endl; 
#define all(a) a.begin(),a.end()

int check(int n,int m,vector<pii> a,vector<pii> c,int k,int pos,vi ans){

    // cout<<pos sp;
    if(pos>=k){
        int c=0;
        vi dp(n+1,0);
        for(auto i:ans){
            dp[i]=1;
            // cout<<i sp;
        }
        // nl;
        for(int i=0;i<m;i++){
            if(dp[a[i].ff]!=0 && dp[a[i].ss]!=0)c++;
        }
        return c;
    }
    vi temp1,temp2;
    for(auto i:ans)temp1.pb(i);
    for(auto i:ans)temp2.pb(i);
    temp1.pb(c[pos].ff);
    temp2.pb(c[pos].ss);

    // print(temp1,temp1.size());
    // nl;
    // print(temp2,temp2.size());
    // nl;
    return max(check(n,m,a,c,k,pos+1,temp1),check(n,m,a,c,k,pos+1,temp2));
   
}

int32_t main(){
    // startTime
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin>>n>>m;

    vector<pii> a(m);
    FOR(i,m){
        cin>>a[i].ff>>a[i].ss;
    }
    int k;
    cin>>k;

    vector<pii> c(k);
    FOR(i,k){
        cin>>c[i].ff>>c[i].ss;
    }

    int ans=check(n,m,a,c,k,0,{});
    cout<<ans;
    // endTime
    return 0;
}
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm> //max,min
#include<iomanip> //setprecision,tuple
#include<vector>  //vector
#include<numeric> //iota
#include<map> //map
#include<set> //set
#include<sstream> //stringstream(hex 16,dec 10,oct 8,bilset 2)
#include<list> //list 
using namespace std;
using lint = long long;
#define INF 2147483647
#define PI acos(-1)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    int n,m;cin>>n>>m;
    vector<pair<int,int>> pa;
    rep(i,m){
        int a,b;cin>>a>>b;
        a--;b--;
        pa.push_back(make_pair(a,b));
    }
    int k;cin>>k;
    vector<pair<int,int>> p;
    rep(i,k){
        int c,d;cin>>c>>d;
        c--;d--;
        p.push_back(make_pair(c,d));
    }
    int ans=0;
    rep(s,1<<k){
        set<int> tmp;
        rep(i,k){
            if(s>>i&1)tmp.insert(p[i].first);
            else tmp.insert(p[i].second);
        }
        int cnt=0;
        for(auto x:pa){
            int tmpa=x.first,tmpb=x.second;
            if(tmp.count(tmpa)&&tmp.count(tmpb))cnt++;
        }
        ans=max(cnt,ans);
    }
    cout<<ans<<endl;
    return 0;
}