#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using ll = long long;
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl

const int mod = 1e9 + 7;

void solve()
{
    int n;
    cin >> n;
    vector<pair<int, int>> x, y;
    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        x.push_back({a, i});
        y.push_back({b, i});
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    vector<pair<int, pair<int, int>>> ans;
    ans.push_back({abs(x[0].first - x[n - 1].first), {min(x[0].second, x[n - 1].second), max(x[0].second, x[n - 1].second)}});
    ans.push_back({abs(x[0].first - x[n - 2].first), {min(x[0].second, x[n - 2].second), max(x[0].second, x[n - 2].second)}});
    ans.push_back({abs(x[1].first - x[n - 1].first), {min(x[1].second, x[n - 1].second), max(x[1].second, x[n - 1].second)}});
    ans.push_back({abs(y[0].first - y[n - 1].first), {min(y[0].second, y[n - 1].second), max(y[0].second, y[n - 1].second)}});
    ans.push_back({abs(y[0].first - y[n - 2].first), {min(y[0].second, y[n - 2].second), max(y[0].second, y[n - 2].second)}});
    ans.push_back({abs(y[1].first - y[n - 1].first), {min(y[1].second, y[n - 1].second), max(y[1].second, y[n - 1].second)}});
    sort(ans.begin(), ans.end());
    for (int i = 4; i >= 0; i--)
    {
        if (ans[5].second != ans[i].second)
        {
            cout << ans[i].first << endl;
            return;
        }
    }
}

int main()
{
    fast;
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <iostream>
#include <fstream>
#include <chrono>

using namespace std;

const int DIV = 998244353;

void solve(int test, std::istream &in) {
    int n, m, k;
    in >> n >> m;
    vector<char> dish(n, 0);
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++) {
        in >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    in >> k;
    vector<int> c(k), d(k);
    for (int i = 0; i < k; i++) {
        in >> c[i] >> d[i];
        c[i]--;
        d[i]--;
    }
    int answer = 0;
    int maxMask = 1 << k;
    for (int mask = 0; mask < maxMask; mask++) {
        int tmp = mask;
        for (int i = 0; i < k; i++) {
            int x = (tmp & 1) ? c[i] : d[i];
            dish[x]++;
            tmp >>= 1;
        }

        int cur = 0;
        for (int i = 0; i < m; i++) {
            if (dish[a[i]] > 0 && dish[b[i]] > 0)
                cur++;
        }
        if (cur > answer)
            answer = cur;

        tmp = mask;
        for (int i = 0; i < k; i++) {
            int x = (tmp & 1) ? c[i] : d[i];
            dish[x]--;
            tmp >>= 1;
        }
    }
    printf("%d\n", answer);
}

int main(int argc, char *argv[]) {
#ifdef VLAD_LOCAL
    ifstream in("in.txt");
    auto start = std::chrono::steady_clock::now();
#else
    istream &in = cin;
#endif
    solve(0, in);
#ifdef VLAD_LOCAL
    auto end = std::chrono::steady_clock::now();
    double seconds = (double)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() / 1000;
    printf("%.3lf seconds\n", seconds);
#endif
	return 0;
}
