#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ALL(v) v.begin(),v.end()
#define dbg(x) cerr << #x << ": " << (x) << endl;
int n,m;
int siz = 1e3;
vector<pair<int,int>> xy, wz;
int main() {
    cin >> n;
    xy.resize(n);
    for (auto& [x,y] : xy) {
        cin >> x >> y;
    }
    cin >> m;
    wz.resize(m);
    for (auto& [x,y] : wz) {
        cin >> x >> y;
    }
    vector<vector<int>> dis(siz, vector<int>(siz, 1e9));
    queue<pair<int,int>> q;
    for (auto [x,y] : xy) {
        dis[y][x] = 0;
        q.emplace(x,y);
    }
    int dx[] = {-1,0,1,0,-1};
    while (q.size()) {
        auto [x,y] = q.front();
        q.pop();
        for (int i = 0; i < 4; ++i) {
            int nx = x + dx[i];
            int ny = y + dx[i+1];
            if (!(0 <= nx && nx < siz && 0 <= ny && ny < siz)) continue;
            if (dis[ny][nx] > dis[y][x] + 1) {
                dis[ny][nx] = dis[y][x] + 1;
                q.emplace(nx, ny);
            }
        }
    }
    int ans = 1e9;
    for (auto [x,y] : wz) {
        ans = min(ans, dis[y][x]);
    }
    cout << ans << '\n';
}