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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
  
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 


#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;
typedef vector<vi> vvi;

const int M = 1e9+7;
const int N = 2e5;
int po(int,int);
int n,m;
int k;
int a[105],b[105],c[20],d[20];
map<int,int> mp;
int ans = 0;
void f(int id){
    if(id == k+1){
        int s = 0;
        FOR(i,1,m+1){
            if(mp[a[i]] > 0 && mp[b[i]] > 0){
                s++;
            }
        }
        ans = max(ans,s);
        return;
    }
    else{
        mp[c[id]]++;
        f(id+1);
        mp[c[id]]--;
        mp[d[id]]++;
        f(id+1);
        mp[d[id]]--;
    }
}

void solve(){
    cin>>n>>m;
    FOR(i,1,m+1){
        cin>>a[i]>>b[i];
    }

    cin>>k;
    FOR(i,1,k+1){
        cin>>c[i]>>d[i];
    }
    f(1);
    
    cout<<ans<<"\n";
    
    

}




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

    int t=1;
    // cin>>t;
    FOR(i,1,t+1){
        //cout<<"Case #"<<i<<": "; 
        solve();
        
    }
    
    return 0;
    
    
}


int po(int a,int b){
    if(b==0) return 1;
    int ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}


#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  int k;
  cin >> k;
  vector<int> c(k), d(k);
  rep(i, k) {
    cin >> c[i] >> d[i];
    c[i]--; d[i]--;
  }

  int ans = 0;
  rep(t, 1<<k) {
    vector<int> v(n, 0);
    rep(i, k) {
      if (t>>i&1) v[c[i]]++;
      else v[d[i]]++;
    }
    
    int cnt = 0;
    rep(i, m) {
      if (v[a[i]] && v[b[i]]) cnt++;
    }
    // rep(i, n) cout << v[i] << endl;
    chmax(ans, cnt);
  }

  cout << ans << endl;
}