#include <iostream>
#include <string>
#include <vector>
#include <utility>
using ll=long long;
using namespace std;

int main(){
    int N,M;
    cin>>N>>M;
    vector<int> A(M);
    vector<int> B(M);
    for(int i=0;i<M;i++){
        cin>>A[i]>>B[i];
        A[i]--;B[i]--;
    }

    int K;
    cin>>K;
    vector<int> C(K);
    vector<int> D(K);
    for(int i=0;i<K;i++){
        cin>>C[i]>>D[i];
        C[i]--;D[i]--;
    }

    int MX=1<<K;
    int ans=0;
    for(int i=0;i<MX;i++){
        vector<int> V(N,0);
        for(int j=0;j<K;j++){
            if(1 & (i>>j)){
                V[C[j]]++;
            }else{
                V[D[j]]++;
            }
        }
        int cnt=0;
        for(int j=0;j<M;j++){
            if(V[A[j]] > 0 && V[B[j]] > 0){
                cnt++;
            }
        }
        if(ans < cnt){
            ans = cnt;
        }
    }
    cout<<ans<<endl;

    return 0;
}
/*                             हरे कृष्ण हरे कृष्ण कृष्ण कृष्ण हरे हरे
                                  हरे राम हरे राम राम राम हरे हरे                                     */
#include<bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define pob pop_back
typedef long long int lli;
#define test lli t; cin>>t; while(t--)
#define ff first
#define ss second
#define F(n) for(lli i=0;i<n;i++)
#define pf pop_front
#define lb lower_bound
#define ub upper_bound
#define setbits(x)  __builtin_popcountll(x)
#define zerobits(x)  __builtin_ctzll(x)
#define bs binary_search
#define all(x) x.begin(),x.end()
#define nl "\n"
#define loop(i,s,n) for(lli i=s;i<n;i++)
#define pp(a)  for(auto x : a)  cout<<x<<" ";  cout<<nl;
#define mem(arr,x) memset(arr,x,sizeof(arr))
#define mod 1000000007
#define inf 1e18
#define tt(n) cin>>n; lli a[n]; loop(i,0,n) cin>>a[i];
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ps(x,y) fixed<<setprecision(y)<<x
lli solve(lli n)
{
 lli r,i;
 while(n!=0)
 {
     r=n%10;
     if(r==7) return -1;
     n/=10;
 }
 return 0;
}
lli decToOctal(lli n)
{
    lli octalNum[100];
    lli i = 0,f=0;
    while (n != 0) {
        octalNum[i] = n % 8;
        n = n / 8;
        i++;
    }
    for (lli j = i - 1; j >= 0; j--)
        {
            if(octalNum[j]==7)
            {
                f=1;
                break;
            }
        }
        if(f) return -1;
        else return 0;
}
int main()
{
fast;
 	lli n,i,j,c,x=0;
 	cin>>n;
 	lli a[n],s=0;
 	loop(i,0,n) cin>>a[i];
 	sort(a,a+n);
 	loop(i,0,n)
 	{
 	    s+=(i*a[i])-((n-1-i)*a[i]);
 	}
 	cout<<s;
return 0;
}