#include<iostream>
#include<stdio.h>
#include<iomanip>
#include<vector>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
#include<utility>
#include<stack>
#include<unordered_map>
#include<map>
#include<set>
#include<unordered_set>
#include<algorithm>
#include<sstream>
#include<stdlib.h>
#include<bitset>
#define ff first
#define ss second
#define mod 1000000007LL
#define PI 3.14159265
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
void func(vector<pair<int,int>>&p,vector<pair<int,int>>&c,int k,vector<int>&s,int &mx) {
    if(k==p.size()) {
        int a=0;
        for(int i=0;i<c.size();i++) {
            if(s[c[i].ff]>=1&&s[c[i].ss]>=1)
                a++;
        }
        if(a>mx)
            mx=a;
    }
    else {
        s[p[k].ff]++;
        func(p,c,k+1,s,mx);
        s[p[k].ss]++;
        s[p[k].ff]--;
        func(p,c,k+1,s,mx);
        s[p[k].ss]--;
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>>c(m);
    for(int i=0;i<m;i++)
        cin>>c[i].ff>>c[i].ss;
    int k;
    cin>>k;
    vector<pair<int,int>>p(k);
    for(int i=0;i<k;i++)
        cin>>p[i].ff>>p[i].ss;
    vector<int>s(n+1,0);
    int mx=0;
    func(p,c,0,s,mx);
    cout<<mx;
}



#include <iostream> 
#include <vector> 
#include <algorithm> 
using namespace std;
typedef long long ll;

int main() {
    int H, W, N, M;
    bool l[1600][1600], f[1600][1600], r[1600][1600];
    cin >> H >> W >> N >> M;
    for (int h = 0; h < H; ++h){
        for (int w = 0; w < W; ++w){
            l[h][w] = false;
            f[h][w] = false;
            r[h][w] = false;
        }
    }
    for (int i = 0; i < N; ++i){
        int a, b;
        cin >> a >> b;
        l[a-1][b-1] = true;
    }
    for (int i = 0; i < M; ++i){
        int c, d;
        cin >> c >> d;
        f[c-1][d-1] = true;
    }

    for (int h = 0; h < H; ++h){
        bool light = false;
        for (int w = 0; w < W; ++w){
            if (l[h][w]) {
                light = true;
            }else if(f[h][w]){
                light = false;
            }
            r[h][w] |= light;
        }
    }

    for (int h = 0; h < H; ++h){
        bool light = false;
        for (int w = W-1; w >= 0; --w){
            if (l[h][w]) {
                light = true;
            }else if(f[h][w]){
                light = false;
            }
            r[h][w] |= light;
        }
    }
    
    for (int w = 0; w < W; ++w){
        bool light = false;
        for (int h = 0; h < H; ++h){
            if (l[h][w]) {
                light = true;
            }else if(f[h][w]){
                light = false;
            }
            r[h][w] |= light;
        }
    }

    for (int w = 0; w < W; ++w){
        bool light = false;
        for (int h = H-1; h >= 0; --h){
            if (l[h][w]) {
                light = true;
            }else if(f[h][w]){
                light = false;
            }
            r[h][w] |= light;
        }
    }

    int res = 0;
    for (int h = 0; h < H; ++h){
        for (int w = 0; w < W; ++w){
            if (r[h][w]) res++;
        }
    }

    cout << res << endl;
    return 0;
}