    #include <bits/stdc++.h>

    using namespace std;
    void solve(){
       int N,M;
       cin>>N>>M;
       vector<pair<int,int>> cond(M);
       for(int i=0; i<M; i++){
            int t1,t2;
            cin>>t1>>t2;
            cond[i]=make_pair(t1,t2);
       }
       int K;
       cin>>K;
       vector<pair<int,int>> person(K);
        for(int i=0; i<K; i++){
            int t1,t2;
            cin>>t1>>t2;
            person[i]=make_pair(t1,t2);
       }
       int last=0;
        vector<int> dishes(N,0);
        for(int i=0; i<(1<<K); i++){
            int temp=0;
            bitset<17> b(i);
            dishes.assign(N,0);
            for(int j=0; j<K; j++){
                if(b[j]==0){
                    dishes[person[j].first-1]++;
                }
                else{
                    dishes[person[j].second-1]++;
                }
            }
            for(auto x: cond){
                if(dishes[x.first-1]>=1 && dishes[x.second-1]>=1){
                    temp++;
                }
            }
            last=max(last,temp);
        }
        cout<<last<<endl;

    }

    int main()
    {
      ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int t=1;
        //cin>>t;
        while(t--){
            solve();
        }

      return 0;
    }

#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli                               long long int
#define ll                                long long
#define FOR(i,a,b)                        for(int i=a;i<b;i++)
#define vi                                vector<int>
#define all(a)                            a.begin(),a.end()
#define sz(a)                             a.size()
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
ll int MM = 998244353;
const int mod = 1e9 + 7;
const int INF = 1e9 + 5;
 
void solve()
{
	int n,m;
	cin >> n >> m;
	vector<pair<int,int>> dish1(m);
	FOR(i,0,m) {
		cin >> dish1[i].first >> dish1[i].second;
	}
	int k;
	cin >> k;
	vector<pair<int,int>> dish2(k);
	FOR(i,0,k) {
		cin >> dish2[i].first >> dish2[i].second;
	}
	int mxans = 0;

	for(int i=0;i<(1<<k);i++)
	{
		int ans = 0;
		map<int,int>mpp;
		for(int j=0;j<k;j++)
		{
			if((1<<j)&i)
			{
				mpp[dish2[j].first]++;
			}
			else
			{
				mpp[dish2[j].second]++;
			}
		}
		FOR(i,0,m)
		{
			if(mpp[dish1[i].first] and mpp[dish1[i].second])
				ans++;
		}
		mxans = max(mxans,ans);
	}
	cout << mxans << "\n";

}

int main()
{
    ios;
    #ifndef ONLINE_JUDGE
    freopen("input2.txt","r",stdin);
    freopen("output2.txt","w",stdout);
    #endif
   
    int t;
    t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
}