#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

ll A[1000], B[1000];
ll C[1000], D[1000];

int main() {
    ll N, M, K;
    cin >> N >> M;
    rep(i, M){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    cin >> K;
    rep(i, K){
        cin >> C[i] >> D[i];
        C[i]--;
        D[i]--;
    }
        
    int ans = 0;
    int X[1000];
    for (ll S = 0; S < 1 << K; S++){
        rep(i, N)X[i] = 0;
        
        rep(i, K){
            if (S >> i & 1){
                X[C[i]] = 1;
            } else {
                X[D[i]] = 1;
            }
        }
        int cnt = 0;
        rep (i, M){
            if (X[A[i]] && X[B[i]]){
                cnt++;
            }
        }
        chmax(ans, cnt);
    }
    cout << ans;       
    return 0;    
}

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back 

#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define decimal(k) cout<<fixed<<setprecision(k)<<endl
#define LL_MAX LLONG_MAX
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int Log2n( int n){ return (n > 1) ? 1 + Log2n(n / 2) : 0;} 
int fac[100009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factors(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); } 
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" ";  cout<<endl;} 

int m,k,n,ans=0;
int a[1000009]={0},b[1000009],c[1000009],d[1000009];
vector<int>v;
// 0-->c
// 1-->d

void printTheArray(int arr[], int n) 
{ 
    map<int,int>mp;
    int cnt=0;
    for (int i = 0; i < n; i++) 
    { 
         if(arr[i]==0)
         {
             mp[c[i]]++;
         }
         else
         {
             mp[d[i]]++;
         }
    } 

    for(int i=0;i<m;i++)
    {
        if(mp[a[i]]*mp[b[i]]!=0)
              cnt++;
    }

   ans=max(ans,cnt);

} 

void generateAllBinaryStrings(int n, int arr[], int i) 
{ 
    if (i == n) { 
        printTheArray(arr, n); 
        return; 
    } 
    arr[i] = 0; 
    generateAllBinaryStrings(n, arr, i + 1); 
  
    arr[i] = 1; 
    generateAllBinaryStrings(n, arr, i + 1); 
} 



signed main()
 {


       run;


int  t=1;
 //cin>>t;
 while(t--)
{

             int  i;


                cin>>n>>m;
               
  
            

              for(i=0;i<m;i++)
              {
                 cin>>a[i];
                cin>>b[i];
              }
             
              cin>>k;

              int arr[k]; 

              for(i=0;i<k;i++)
              {
                 cin>>c[i];
                 cin>>d[i];
              }  

        generateAllBinaryStrings(k,arr,0); 
      cout<<ans<<endl;




}
}