#include<bits/stdc++.h>

#define SORT(v) sort(v.begin(),v.end())
#define si(n) scanf("%d",&n)
#define sii(n,m) scanf("%d %d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld %lld",&n,&m)
#define ss(cad) scanf("%s",cad)
#define all(v) (v).begin(), (v).end()
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl; 
#define M 1000000007
#define N_MAX 100010

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vp;

int main(){
	int n, m;
	sii(n, m);
	pi vec[m+1];
	for(int i = 0; i < m; i++)
		sii(vec[i].fst, vec[i].scn);
	int k;
	si(k);
	pi ttt[k+1];
	for(int i = 0; i < k; i++)
		sii(ttt[i].fst, ttt[i].scn);

	bool posi[n+10];
	int ans = 0;
	for(int mask = 0; mask < (1<<k); mask++){
		memset(posi, 0, sizeof(posi));
		for(int i = 0; i < k; i++)
			if(mask&(1<<i))
				posi[ttt[i].fst] = 1;
			else
				posi[ttt[i].scn] = 1;
		int cnt = 0;
		for(int i = 0; i < m; i++)
			if(posi[vec[i].fst] && posi[vec[i].scn])
				cnt++;
		ans = max(ans, cnt);
	}
	printf("%d\n", ans);
	return 0;
}

#include<iostream>
#include<vector>
#include<map> 
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
#include<cstring>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)

#define fi first
#define se second

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstring = vector<string>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
//const ll MOD = 998244353;
const ll MOD = 1000000007;
const int dc[9] = {1, -1, 0,  0, 1, -1,  1, -1, 0};
const int dr[9] = {0,  0, 1, -1, 1,  1, -1, -1, 0};

template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) { 
    for(auto &v : vec) { is >> v; } return is; 
}
template<typename T> inline 
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";} return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; } return os;
}
template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) { 
    return o << "{" << p.first << "," << p.second << "}"; 
}

template<typename T> inline void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline void chmax(T &a, T b) { a = max(a, b); }

bool solve(ll a, ll b, ll c, ll d)
{
    if(a+b == c+d) { return true; }
    if(a-b == c-d) { return true; }
    if(abs(a-c) + abs(b-d) <= 3) { return true; }
    return false;
}

int main(void)
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    if(a == c && b == d) { 
        cout << 0 << endl;
        return 0;
    }
    
    vector<pll> goal;
    
    if(solve(a,b,c,d)) { 
        cout << 1 << endl;
        return 0;
    }

    if((a+b)%2 == (c+d)%2) { cout << 2 << endl; return 0 ; }

    for(int i = -2; i <= 2; i++) {
        for(int j = -2; j <= 2; j++) {
            goal.push_back({c+i,d+j});
        }
    }

    goal.push_back({c-3,d});
    goal.push_back({c+3,d});
    goal.push_back({c,d-3});
    goal.push_back({c,d+3});

    int n = goal.size();

    rep(i,n) {
        pll g = goal[i];
        ll c2 = g.fi, d2 = g.se;
        if(solve(a,b,c2,d2)) { 
            cout << 2 << endl;
            return 0;
        }
    }
    cout << 3 << endl;

    return 0;

} /*atcoder*/
