#include using namespace std; #define int long long const int N = 2e5 + 5, M = 1e3 + 5; int n, x[N], y[N], m, ans = 1e18, l[M][M], r[M][M]; vector v[N]; signed main() { for (int i = 0; i <= 1000; i++) { v[i].push_back(-1e18); v[i].push_back(1e18); } cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; } cin >> m; for (int i = 1, _x, _y; i <= m; i++) { cin >> _x >> _y; v[_x].push_back(_y); } for (int i = 0; i <= 1000; i++) { sort(v[i].begin(), v[i].end()); for (int j = 0; j <= 1000; j++) { auto tmp = upper_bound(v[i].begin(), v[i].end(), j) - v[i].begin() - 1; l[i][j] = v[i][tmp]; tmp = lower_bound(v[i].begin(), v[i].end(), j) - v[i].begin(); r[i][j] = v[i][tmp]; } } for (int i = 1; i <= n; i++) { for (int j = 0; j <= 1000; j++) { ans = min(ans, abs(x[i] - j) + min(y[i] - l[j][y[i]], r[j][y[i]] - y[i])); } } cout << ans; return 0; } /* */