#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>
#include <climits>
#include <bitset>
#include <cassert>


// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

template<class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
template<class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }

const double EPS = 1e-9;

struct point {
	double x, y;
	point() :x(0), y(0) {}
	point(double x, double y) :x(x), y(y) {}
	point(const point& p) :x(p.x), y(p.y) {}

	point operator+ (const point& p) const {
		return point(x + p.x, y + p.y);
	}

	point operator- (const point& p) const {
		return point(x - p.x, y - p.y);
	}

	point operator* (const double s) const {
		return point(x * s, y * s);
	}

	point operator* (const point& p) const {
		return point(x * p.x - y * p.y, x * p.y + y * p.x);
	}

	point operator/ (const double s) const {
		return point(x / s, y / s);
	}

	bool operator< (const point& p) const {
		return x + EPS < p.x || abs(x - p.x) < EPS && y + EPS < p.y;
	}

	bool operator== (const point& p) const {
		return abs(x - p.x) < EPS && abs(y - p.y) < EPS;
	}
};

point rotate90(const point& p) {
	return point(-p.y, p.x);
}

point rotate(const point& p, const double theta) {
	const double s = sin(theta), c = cos(theta);
	return point(c * p.x - s * p.y, s * p.x + c * p.y);
}

double angle(const point& p) {
	return atan2(p.y, p.x);
}

double abs(const point& p) {
	return sqrt(p.x * p.x + p.y * p.y);
}

double norm(const point& p) {
	return p.x * p.x + p.y * p.y;
}

double dot(const point& l, const point& r) {
	return l.x * r.x + l.y * r.y;
}

double cross(const point& l, const point& r) {
	return l.x * r.y - l.y * r.x;
}

struct line {
	point a, b;
	line(point a, point b) :a(a), b(b){}
};

struct segment {
	point a, b;
	segment(point a, point b) :a(a), b(b){}
};

struct circle {
	point c;
	double r;
	circle(point c, double r) :c(c), r(r){}
};

typedef vector<point> polygon;

int ccw(const point& a, point b, point c) {
	b = b - a;
	c = c - a;
	if (cross(b, c) > EPS) return 1; // ccw
	if (cross(b, c) < -EPS) return -1; // cw
	if (dot(b, c) < 0) return 2; // c, a, b 順に一直線上
	if (norm(b) < norm(c)) return -2; // a, b, c 順に一直線上
	return 0; //a, c, b 順で一直線上
}

point projection(const line& l, const point& p) {
	const point dif = l.b - l.a;
	const double tmp = dot(p - l.a, dif) / norm(dif);
	return l.a + dif * tmp;
}

bool intersect(const line& l, const line& m) {
	return abs(cross(l.b - l.a, m.b - m.a)) > EPS || abs(cross(l.b - l.a, m.b - l.a)) < EPS;
}

bool intersect(const line& l, const segment& s) {
	return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS;
}

bool intersect(const line& l, const point& p) {
	return abs(ccw(l.a, l.b, p)) != -1;
}

bool intersect(const segment& s, const segment& t) {
	return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
		ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

bool intersect(const segment& s, const point& p) {
	return ccw(s.a, s.b, p) == 0;
}

bool intersect(const circle& c, const point& p) {
	return abs(c.c - p) <= c.r + EPS;
}

bool intersect(const circle& c, const circle& d) {
	return abs(c.c - d.c) <= c.r + d.r && abs(c.c - d.c) >= abs(c.r - d.r);
}

double dist(const point& a, const point& b) {
	return abs(a - b);
}

double dist(const line& l, const point& p) {
	return abs(p - projection(l, p));
}

double dist(const line& l, const line& m) {
	return intersect(l, m) ? 0 : dist(l, m.a);
}

double dist(const line& l, const segment& s) {
	return intersect(l, s) ? 0 : min(dist(l, s.a), dist(l, s.b));
}

double dist(const segment& s, const point& p) {
	const point tmp = projection(line(s.a, s.b), p);
	return intersect(s, tmp) ? abs(tmp - p) : min(abs(s.a - p), abs(s.b - p));
}

double dist(const segment& s, const segment& t) {
	if (intersect(s, t))
		return 0;
	return min(min(dist(s, t.a), dist(s, t.b)), min(dist(t, s.a), dist(t, s.b)));
}

point crosspoint(const line& l, const line& m) {
	const double tmp = cross(l.b - l.a, m.b - m.a);
	if (abs(tmp) < EPS) // 平行
		return l.a;
	return l.a + (l.b - l.a) * cross(m.b - m.a, m.b - l.a) * (1.0 / tmp);
}

point crosspoint(const segment& s, const segment& t) {
	if (!intersect(s, t)) // 交点を持たない
		return s.a; // 用改善

	const double tmp = cross(s.b - s.a, t.b - t.a);
	if (abs(tmp) < EPS) { // 一直線上
		if (intersect(s, t.a)) return t.a;
		if (intersect(s, t.b)) return t.b;
		if (intersect(t, s.a)) return s.a;
		return s.b;
	}

	return t.a + (t.b - t.a) * cross(s.b - s.a, s.b - t.a) * (1.0 / tmp);
}

vector<point> crosspoint(const circle &c, const circle& d) {
	vector<point> res;
	if (abs(c.c - d.c) < EPS) // 中心の座標が同じ
		return res;

	const double tmp = abs(c.c - d.c);
	const double rc = (tmp * tmp + c.r * c.r - d.r * d.r) / (tmp + tmp);
	const double rs = sqrt(c.r * c.r - rc * rc);
	const point diff = (d.c - c.c) / tmp;
	res.push_back(point(c.c + diff * point(rc, rs)));
	res.push_back(point(c.c + diff * point(rc, -rs)));
	return res;
}

vector<point> crosspoint(const circle& c, const line& l) {
	vector<point> res;
	const point h = projection(l, c.c);
	const double d = abs(h - c.c);
	if (d > c.r - EPS) {
		res.push_back(h);
	}
	else if (d <= c.r - EPS) {
		point v = l.b - l.a;
		v = v * sqrt(c.r * c.r - d * d) / abs(v);
		res.push_back(h + v);
		res.push_back(h - v);
	}

	return res;
}

vector<point> crosspoint(const circle& c, const segment& s) {
	vector<point> res;
	vector<point> tmp = crosspoint(c, line(s.a, s.b));
	for (int i = 0; i < tmp.size(); ++i)
	if (intersect(s, tmp[i]))
		res.push_back(tmp[i]);

	return res;
}

double area(const polygon& p) {
	double res = 0.0;
	const int num = p.size();
	for (int i = 0; i < num; ++i) {
		res += cross(p[i], p[(i + 1) % num]);
	}

	return res * 0.5;
}

bool contain(const polygon& p, const point& a) {
	for (int i = 0; i < p.size(); ++i)
	if (p[i] == a)
		return true;

	vector<point> points;
	points.push_back(a);

	const segment seg(point(0, a.y), point(10001, a.y));
	for (int i = 0; i < p.size(); ++i) {
		const segment edge(p[i], p[(i + 1) % p.size()]);
		if (intersect(seg, edge))
			points.push_back(crosspoint(seg, edge));
	}

	if (points.size() < 3)
		return false;

	sort(points.begin(), points.end());

	return points[1] == a;
}

bool contain(const circle& c, const polygon& p) {
	for (int i = 0; i < p.size(); ++i)
	if (dist(c.c, p[i]) > c.r)
		return false;

	return true;
}

bool contain(const polygon& p, const circle& c) {
	if (!contain(p, c.c))
		return false;

	for (int i = 0; i < p.size(); ++i)
	if (dist(segment(p[i], p[(i + 1) % p.size()]), c.c) < c.r)
		return false;

	return true;
}

bool intersect(const polygon& p, const circle& c) {
	for (int i = 0; i < p.size(); ++i)
	if (dist(segment(p[i], p[(i + 1) % p.size()]), c.c) <= c.r)
		return true;

	return false;
}

int main(){
	int n;
	cin >> n;
	vector<point> p1;
	p1.push_back(point(0, 0));
	rep(i, n){
		int x, y;
		cin >> x >> y;
		p1.push_back(point(x, y));
	}
	p1.push_back(point(1000, 0));
	vector<segment> l1;
	rep(i, p1.size() - 1){
		l1.push_back(segment(p1[i], p1[i + 1]));
	}

	int m;
	cin >> m;
	vector<point> p2;
	p2.push_back(point(0, 1000));
	rep(i, m){
		int x, y;
		cin >> x >> y;
		p2.push_back(point(x, y));
	}
	p2.push_back(point(1000, 1000));
	vector<segment> l2;
	rep(i, p2.size() - 1){
		l2.push_back(segment(p2[i], p2[i + 1]));
	}

	double ans = 1e9;
	for (auto p : p1){
		for (auto pp : p2){
			ans = min(ans, dist(p, pp));
		}
		for (auto ll : l2){
			ans = min(ans, dist(ll, p));
		}
	}

	for (auto l : l1){
		for (auto pp : p2){
			ans = min(ans, dist(l, pp));
		}
		for (auto ll : l2){
			ans = min(ans, dist(l, ll));
		}
	}

	cout.setf(ios::fixed);
	cout.precision(10);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1288