Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.

Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l_{1, }i, r_{1, }i). Also he has m variants when he will attend programming classes, i-th variant is given by a period of time (l_{2, }i, r_{2, }i).

Anton needs to choose exactly one of n possible periods of time when he will attend chess classes and exactly one of m possible periods of time when he will attend programming classes. He wants to have a rest between classes, so from all the possible pairs of the periods he wants to choose the one where the distance between the periods is maximal.

The distance between periods (l_1, r_1) and (l_2, r_2) is the minimal possible distance between a point in the first period and a point in the second period, that is the minimal possible |i - j|, where l_1 ≤ i ≤ r_1 and l_2 ≤ j ≤ r_2. In particular, when the periods intersect, the distance between them is 0.

Anton wants to know how much time his rest between the classes will last in the best case. Help Anton and find this number!


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of time periods when Anton can attend chess classes.

Each of the following n lines of the input contains two integers l_{1, }i and r_{1, }i (1 ≤ l_{1, }i ≤ r_{1, }i ≤ 10^9) — the i-th variant of a period of time when Anton can attend chess classes.

The following line of the input contains a single integer m (1 ≤ m ≤ 200 000) — the number of time periods when Anton can attend programming classes.

Each of the following m lines of the input contains two integers l_{2, }i and r_{2, }i (1 ≤ l_{2, }i ≤ r_{2, }i ≤ 10^9) — the i-th variant of a period of time when Anton can attend programming classes.


-----Output-----

Output one integer — the maximal possible distance between time periods.


-----Examples-----
Input
3
1 5
2 6
2 3
2
2 4
6 8

Output
3

Input
3
1 5
2 6
3 7
2
2 4
1 4

Output
0



-----Note-----

In the first sample Anton can attend chess classes in the period (2, 3) and attend programming classes in the period (6, 8). It's not hard to see that in this case the distance between the periods will be equal to 3.

In the second sample if he chooses any pair of periods, they will intersect. So the answer is 0.

Source: codeforces | Difficulty: EASY
Tags: Sorting

Greedy algorithms


Solutions:
n = int(input())
a = [[], []]
for i in range(n):
	(q, w) = [int(x) for x in input().split()]
	a[0].append(q)
	a[1].append(w)
n = int(input())
b = [[], []]
for i in range(n):
	(q, w) = [int(x) for x in input().split()]
	b[0].append(q)
	b[1].append(w)
enda = min(a[1])
stb = max(b[0])
endb = min(b[1])
sta = max(a[0])
if stb - enda > sta - endb:
	if stb - enda > 0:
		print(stb - enda)
	else:
		print(0)
elif sta - endb > 0:
	print(sta - endb)
else:
	print(0)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = [LI() for _ in range(n)]
	m = I()
	b = [LI() for _ in range(m)]
	al = max(map(lambda x: x[0], a))
	ar = min(map(lambda x: x[1], a))
	bl = max(map(lambda x: x[0], b))
	br = min(map(lambda x: x[1], b))
	r = max([0, al - br, bl - ar])
	return r
print(main())


n = int(input())
x1 = 0
y1 = 10 ** 10
x2 = 0
y2 = 10 ** 10
for i in range(n):
	(x, y) = map(int, input().split())
	if x > x1:
		x1 = x
	if y < y1:
		y1 = y
m = int(input())
for i in range(m):
	(x, y) = map(int, input().split())
	if x > x2:
		x2 = x
	if y < y2:
		y2 = y
ans = max(x2 - y1, x1 - y2)
if ans < 0:
	print(0)
else:
	print(ans)


n = int(input())
(mb, mb1) = [1000000000] * 2
(ma, ma1) = [0] * 2
for i in range(n):
	(a, b) = map(int, input().split())
	if mb > b:
		mb = b
	if ma1 < a:
		ma1 = a
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	if ma < a:
		ma = a
	if mb1 > b:
		mb1 = b
if ma - mb <= 0 and ma1 - mb1 <= 0:
	print('0')
else:
	print(max(ma1 - mb1, ma - mb))


import sys
from collections import defaultdict
shapes = defaultdict(int)
chess_starts = list()
chess_ends = list()
prog_starts = list()
prog_ends = list()
n1 = int(sys.stdin.readline())
for i in range(n1):
	input = sys.stdin.readline().strip().split()
	chess_starts.append(int(input[0]))
	chess_ends.append(int(input[1]))
n2 = int(sys.stdin.readline())
for i in range(n2):
	input = sys.stdin.readline().strip().split()
	prog_starts.append(int(input[0]))
	prog_ends.append(int(input[1]))
max_prog_start = max(prog_starts)
min_prog_end = min(prog_ends)
max_chess_start = max(chess_starts)
min_chess_end = min(chess_ends)
max_a = 0
max_b = 0
if min_prog_end < min_chess_end:
	max_a = max_chess_start - min_prog_end
else:
	max_a = max_prog_start - min_chess_end
if max_prog_start < max_chess_start:
	max_b = max_chess_start - min_prog_end
else:
	max_b = max_prog_start - min_chess_end
if max(max_a, max_b) < 0:
	print(0)
else:
	print(max(max_a, max_b))


n = int(input())
maxl1 = 0
minr1 = 100000000000000
for _ in range(0, n):
	(a, b) = list(map(int, input().split()))
	maxl1 = max(a, maxl1)
	minr1 = min(b, minr1)
n = int(input())
maxl2 = 0
minr2 = 100000000000000
for _ in range(0, n):
	(a, b) = list(map(int, input().split()))
	maxl2 = max(a, maxl2)
	minr2 = min(b, minr2)
print(max(max(0, maxl1 - minr2), max(0, maxl2 - minr1)))


import sys
MAX = 10000000000.0
n = int(input())
l1 = []
min1 = MAX
max1 = 0
for i in range(n):
	(l, r) = map(int, sys.stdin.readline().split())
	min1 = min(min1, r)
	max1 = max(max1, l)
	l1.append((l, r))
m = int(input())
l2 = []
max2 = 0
min2 = MAX
for i in range(m):
	(l, r) = map(int, sys.stdin.readline().split())
	max2 = max(max2, l)
	min2 = min(min2, r)
	l2.append((l, r))
ans = 0
if max2 > min1:
	ans = max2 - min1
ans = max(ans, max1 - min2)
print(ans)


chessleft = []
chessright = []
compleft = []
compright = []
chno = int(input())
for i in range(chno):
	(l, r) = [int(x) for x in input().split()]
	chessleft.append(l)
	chessright.append(r)
compno = int(input())
for i in range(compno):
	(l, r) = [int(x) for x in input().split()]
	compleft.append(l)
	compright.append(r)
chessleft.sort()
chessright.sort()
compleft.sort()
compright.sort()
chessfirst = compleft[-1] - chessright[0]
compfirst = chessleft[-1] - compright[0]
ans = max(chessfirst, compfirst)
if ans <= 0:
	print(0)
else:
	print(ans)


a = []
b = []
c = []
d = []
ans = 0
n = int(input())
for _ in range(0, n):
	(s, e) = map(int, input().split())
	a.append(s)
	b.append(e)
m = int(input())
for _ in range(0, m):
	(s, e) = map(int, input().split())
	c.append(s)
	d.append(e)
ans = max(ans, max(max(c) - min(b), max(a) - min(d)))
print(ans)


from sys import stdin, stdout

def ri():
	return map(int, input().split())
n = int(input())
minnr = 10 ** 9 + 1
maxnl = -1
minmr = 10 ** 9 + 1
maxml = -1
for i in range(n):
	(l, r) = ri()
	minnr = min(minnr, r)
	maxnl = max(maxnl, l)
m = int(input())
for i in range(m):
	(l, r) = ri()
	minmr = min(minmr, r)
	maxml = max(maxml, l)
ans = 0
if minnr <= maxml:
	ans = maxml - minnr
else:
	ans = 0
if minmr <= maxnl:
	ans = max(ans, maxnl - minmr)
print(ans)


n = int(input())
chess_left = (1000000000.0, 1000000000.0 + 1)
chess_right = (-1, 0)
for i in range(n):
	[l, r] = list(map(int, input().split()))
	if r < chess_left[1]:
		chess_left = (l, r)
	if l > chess_right[0]:
		chess_right = (l, r)
m = int(input())
prog_left = (1000000000.0, 1000000000.0 + 1)
prog_right = (-1, 0)
for i in range(m):
	[l, r] = list(map(int, input().split()))
	if r < prog_left[1]:
		prog_left = (l, r)
	if l > prog_right[0]:
		prog_right = (l, r)
cand1 = max(0, prog_right[0] - chess_left[1])
cand2 = max(0, chess_right[0] - prog_left[1])
print(max(cand1, cand2))


n = int(input())
(l1, r1, l2, r2) = ([], [], [], [])
for i in range(n):
	(l, r) = map(int, input().split())
	l1.append(l)
	r1.append(r)
m = int(input())
for j in range(m):
	(l, r) = map(int, input().split())
	l2.append(l)
	r2.append(r)
a = max(-min(r1) + max(l2), -min(r2) + max(l1))
if a > 0:
	print(a)
else:
	print(0)


input = __import__('sys').stdin.readline
n = int(input())
lis1 = []
lis2 = []
for i in range(n):
	(a, b) = map(int, input().split())
	lis1.append([b, a])
m = int(input())
for j in range(m):
	(a, b) = map(int, input().split())
	lis2.append([a, b])
lis1.sort()
lis2.sort()
ans = max(0, lis2[-1][0] - lis1[0][0])
for i in range(n):
	(lis1[i][0], lis1[i][1]) = (lis1[i][1], lis1[i][0])
for i in range(m):
	(lis2[i][0], lis2[i][1]) = (lis2[i][1], lis2[i][0])
lis1.sort()
lis2.sort()
ans = max(0, ans, lis1[-1][0] - lis2[0][0])
print(ans)


def list_inp(n):
	out_list = []
	for i in range(n):
		out_list.append(list(map(int, input().split(' '))))
	return out_list
chess = list_inp(int(input()))
prog = list_inp(int(input()))

def max_rs(list_1, list_2):
	rs = max([l2_st[0] for l2_st in list_2]) - min([l1_end[1] for l1_end in list_1])
	if rs < 0:
		rs = 0
	return rs
print(max(max_rs(chess, prog), max_rs(prog, chess)))


def binary_search_first_true(predicate, from_inclusive, to_inclusive):
	lo = from_inclusive - 1
	hi = to_inclusive + 1
	while hi - lo > 1:
		mid = (lo + hi) // 2
		if not predicate(mid):
			lo = mid
		else:
			hi = mid
	return hi

def main(sc):
	n = sc.next_int()
	(mi, ma) = (10 ** 9 + 1, 0)
	for i in range(n):
		(l, r) = sc.next_ints(2)
		mi = min(mi, r)
		ma = max(ma, l)
	ans = 0
	m = sc.next_int()
	for i in range(m):
		(l, r) = sc.next_ints(2)
		d1 = max(ma - r, 0)
		d2 = max(l - mi, 0)
		ans = max(ans, max(d1, d2))
	print(ans)

class Scanner:

	def __init__(self):
		self.idx = 0
		self.tokens = []

	def next(self):
		while self.idx == len(self.tokens) or not len(self.tokens[self.idx]):
			if self.idx == len(self.tokens):
				self.idx = 0
				self.tokens = input().split()
			else:
				self.idx += 1
		self.idx += 1
		return self.tokens[self.idx - 1]

	def next_string(self):
		return self.next()

	def next_strings(self, n):
		return [self.next_string() for i in range(0, n)]

	def next_int(self):
		return int(self.next())

	def next_ints(self, n):
		return [self.next_int() for i in range(0, n)]
scanner = Scanner()
main(scanner)


def intersect(a, b, c, d):
	return not (b < c or a > d)
n = int(input())
chess = []
chess_rev = []
for i in range(n):
	(a, b) = [int(j) for j in input().split()]
	chess.append((a, b))
	chess_rev.append((b, a))
m = int(input())
prog = []
prog_rev = []
for i in range(m):
	(a, b) = [int(j) for j in input().split()]
	prog.append((a, b))
	prog_rev.append((b, a))
chess = sorted(chess)
prog = sorted(prog)
chess_rev = sorted(chess_rev)
prog_rev = sorted(prog_rev)
cf = (chess_rev[0][1], chess_rev[0][0])
cl = chess[-1]
pf = (prog_rev[0][1], prog_rev[0][0])
pl = prog[-1]
r = 0
if not intersect(cf[0], cf[1], pl[0], pl[1]):
	if cf[1] < pl[0]:
		r = max(r, pl[0] - cf[1])
	if cf[0] > pl[1]:
		r = max(r, cf[0] - pl[1])
if not intersect(cl[0], cl[1], pf[0], pf[1]):
	if cl[0] > pf[1]:
		r = max(r, cl[0] - pf[1])
	if cl[1] < pf[0]:
		r = max(r, pf[0] - cl[1])
print(r)


import sys
n = int(input())
(min1, max1) = (sys.maxsize, 0)
for i in range(n):
	(a, b) = map(int, input().split())
	max1 = max(a, max1)
	min1 = min(b, min1)
m = int(input())
(min2, max2) = (sys.maxsize, 0)
for i in range(m):
	(a, b) = map(int, input().split())
	max2 = max(a, max2)
	min2 = min(b, min2)
res = max(max2 - min1, 0)
res = max(max1 - min2, res)
print(res)


n = int(input())
max_chess_start = -1
min_chess_end = 10000000001
for i in range(n):
	(start, end) = [int(x) for x in input().split()]
	if start > max_chess_start:
		max_chess_start = start
	if end < min_chess_end:
		min_chess_end = end
m = int(input())
max_program_start = -1
min_program_end = 10000000001
for i in range(m):
	(start, end) = [int(x) for x in input().split()]
	if start > max_program_start:
		max_program_start = start
	if end < min_program_end:
		min_program_end = end
a = max_program_start - min_chess_end
if a < 0:
	a = 0
b = max_chess_start - min_program_end
if b < 0:
	b = 0
if a == 0 and b == 0:
	print(0)
	exit()
else:
	print(max([a, b]))


n = int(input())
(a1, b1) = (0, 10 ** 10)
for _ in range(n):
	(x, y) = map(int, input().split())
	a1 = max(a1, x)
	b1 = min(b1, y)
m = int(input())
m1 = 0
for _ in range(m):
	(x, y) = map(int, input().split())
	m1 = max(m1, a1 - y)
	m1 = max(m1, x - b1)
print(m1)


l1 = [[int(x.strip().rstrip()) for x in input().split()] for _ in range(int(input()))]
l2 = [[int(x.strip().rstrip()) for x in input().split()] for _ in range(int(input()))]
r1 = max(0, max((x[0] for x in l2)) - min([x[1] for x in l1]))
r2 = max(0, max((x[0] for x in l1)) - min([x[1] for x in l2]))
print(max(r1, r2))


n = int(input())
earliest_finish_chess = 2000000000
latest_start_chess = 0
earliest_finish_prog = 2000000000
latest_start_prog = 0
i = 0
while i < n:
	time = [int(x) for x in input().split()]
	if earliest_finish_chess > time[1]:
		earliest_finish_chess = time[1]
	if latest_start_chess < time[0]:
		latest_start_chess = time[0]
	i += 1
m = int(input())
i = 0
while i < m:
	time = [int(x) for x in input().split()]
	if latest_start_prog < time[0]:
		latest_start_prog = time[0]
	if earliest_finish_prog > time[1]:
		earliest_finish_prog = time[1]
	i += 1
if latest_start_prog - earliest_finish_chess <= 0:
	if latest_start_chess - earliest_finish_prog > 0:
		print(latest_start_chess - earliest_finish_prog)
	else:
		print(0)
elif latest_start_prog - earliest_finish_chess > latest_start_chess - earliest_finish_prog:
	print(latest_start_prog - earliest_finish_chess)
else:
	print(latest_start_chess - earliest_finish_prog)


book = dict()
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	book[0] = max(book.setdefault(0, a), a)
	book[1] = min(book.setdefault(1, b), b)
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	book[2] = max(book.setdefault(2, a), a)
	book[3] = min(book.setdefault(3, b), b)
print(max(0, book[0] - book[3], book[2] - book[1]))


class Solver:

	def run(self):
		n = int(input())
		s1 = [tuple(map(int, input().split())) for _ in range(0, n)]
		m = int(input())
		s2 = [tuple(map(int, input().split())) for _ in range(0, m)]
		l1 = min((i[1] for i in s1))
		r1 = max((i[0] for i in s1))
		l2 = min((i[1] for i in s2))
		r2 = max((i[0] for i in s2))
		l = lambda l, r: max(0, r - l)
		print(max(l(l1, r2), l(l2, r1)))
Solver().run()


__author__ = 'Alexander'

def Task(n) -> int:
	res = 0
	return res

def CollectData(n):
	values = [10 ** 9, 0]
	for i in range(n):
		tup = [int(x) for x in input().split()]
		values[0] = min(values[0], tup[1])
		values[1] = max(values[1], tup[0])
	return values

def Main():
	n = input()
	val1 = CollectData(int(n))
	m = input()
	val2 = CollectData(int(m))
	print(max(val2[1] - val1[0], val1[1] - val2[0], 0))

def Test():
	assert Task() == 1
	assert Task() == 2
Main()


n = int(input())
a = [[]] * 2
a[0] = [0] * n
a[1] = [0] * n
for i in range(0, n):
	(a[0][i], a[1][i]) = map(int, input().split())
m = int(input())
b = [[]] * 2
b[0] = [0] * m
b[1] = [0] * m
for i in range(0, m):
	(b[0][i], b[1][i]) = map(int, input().split())
a[0].sort()
a[1].sort()
b[0].sort()
b[1].sort()
mx = 0
mx = max(b[0][m - 1] - a[1][0], a[0][n - 1] - b[1][0], 0)
print(mx)


import sys

def calc_max_span():
	(chess_first, chess_last) = (10 ** 10, -1)
	(prog_first, prog_last) = (10 ** 10, -1)
	n = int(sys.stdin.readline())
	for i in range(n):
		(l, r) = str(sys.stdin.readline()).split()
		(l, r) = (int(l), int(r))
		chess_first = r if r < chess_first else chess_first
		chess_last = l if l > chess_last else chess_last
	m = int(sys.stdin.readline())
	for i in range(m):
		(l, r) = str(sys.stdin.readline()).split()
		(l, r) = (int(l), int(r))
		prog_first = r if r < prog_first else prog_first
		prog_last = l if l > prog_last else prog_last
	max_span = 0
	if prog_last - chess_first > max_span:
		max_span = prog_last - chess_first
	if chess_last - prog_first > max_span:
		max_span = chess_last - prog_first
	return max_span
max_span = calc_max_span()
print(max_span)


n = int(input())
(L1, R1) = (-1, 100000000000)
for i in range(n):
	(L, R) = map(int, input().split())
	(L1, R1) = (max(L1, L), min(R1, R))
m = int(input())
(L2, R2) = (-1, 100000000000)
for i in range(m):
	(L, R) = map(int, input().split())
	(L2, R2) = (max(L2, L), min(R2, R))
print(max(0, L2 - R1, L1 - R2))


n = int(input())
(mnc, mxc, mnp, mxp) = (10000000000.0, 0, 10000000000.0, 0)
for i in range(n):
	(a, b) = list(map(int, input().split()))
	mxc = max(mxc, a)
	mnc = min(mnc, b)
n2 = int(input())
for i in range(n2):
	(a, b) = list(map(int, input().split()))
	mxp = max(mxp, a)
	mnp = min(mnp, b)
val = max(mxp - mnc, mxc - mnp)
if val < 0:
	print(0)
else:
	print(val)


n = int(input())
l1 = []
r1 = []
l2 = []
r2 = []
for i in range(n):
	(x, y) = map(int, input().split())
	l1.append(x)
	r1.append(y)
m = int(input())
for i in range(m):
	(x, y) = map(int, input().split())
	l2.append(x)
	r2.append(y)
l1_min = min(l1)
l1_max = max(l1)
r1_min = min(r1)
r1_max = max(r1)
l2_min = min(l2)
l2_max = max(l2)
r2_min = min(r2)
r2_max = max(r2)
temp = l2_max - r1_min
temp1 = l1_max - r2_min
print(max(temp, temp1, 0))


import sys
n = int(input())
min = sys.maxsize
max1 = 0
for _ in range(n):
	(a, b) = map(int, input().split())
	if min > b:
		min = b
	if max1 < a:
		max1 = a
m = int(input())
max = 0
min1 = sys.maxsize
for _ in range(m):
	(a, b) = map(int, input().split())
	if max < a:
		max = a
	if min1 > b:
		min1 = b
if max <= min:
	ans = 0
else:
	ans = max - min
if max1 <= min1:
	ans1 = 0
else:
	ans1 = max1 - min1
if ans > ans1:
	print(ans)
else:
	print(ans1)


n = int(input())
n1 = [[int(x) for x in input().split()] for _ in range(n)]
m = int(input())
m1 = [[int(x) for x in input().split()] for _ in range(m)]
a = -min((n1[i][1] for i in range(n))) + max((m1[j][0] for j in range(m)))
b = -min((m1[i][1] for i in range(m))) + max((n1[j][0] for j in range(n)))
print(max(max(a, b), 0))


n = int(str(input()).strip())
min_i_r = 10 ** 9 + 1
max_i_l = 0
for _ in range(n):
	(l, r) = str(input()).strip().split(' ', 1)
	min_i_r = min(min_i_r, int(r))
	max_i_l = max(max_i_l, int(l))
m = int(str(input()).strip())
min_j_r = 10 ** 9 + 1
max_j_l = 0
for _ in range(m):
	(l, r) = str(input()).strip().split(' ', 1)
	min_j_r = min(min_j_r, int(r))
	max_j_l = max(max_j_l, int(l))
ans = max(max_j_l - min_i_r, max_i_l - min_j_r)
print(ans if ans > 0 else 0)


n = int(input())
(earliestFinishChess, latestStartChess) = (10 ** 12, -1)
for i in range(n):
	(s, f) = map(int, input().split())
	earliestFinishChess = min(earliestFinishChess, f)
	latestStartChess = max(latestStartChess, s)
m = int(input())
(earliestFinishProgramming, latestStartProgramming) = (10 ** 12, -1)
for i in range(m):
	(s, f) = map(int, input().split())
	earliestFinishProgramming = min(earliestFinishProgramming, f)
	latestStartProgramming = max(latestStartProgramming, s)
print(max(0, latestStartChess - earliestFinishProgramming, latestStartProgramming - earliestFinishChess))


n = int(input())
INF = float('inf')
(p1, p2) = (0, INF)
for i in range(n):
	(q1, q2) = map(int, input().split())
	p1 = max(p1, q1)
	p2 = min(p2, q2)
m = int(input())
(c1, c2) = (0, INF)
for i in range(m):
	(q1, q2) = map(int, input().split())
	c1 = max(c1, q1)
	c2 = min(c2, q2)
print(max(0, max(c1 - p2, p1 - c2)))


arrn = []
arrm = []
maxstn = -1
minendn = 10 ** 10
maxstm = -1
minendm = 10 ** 10
n = int(input())
for i in range(n):
	arrn.append([int(x) for x in input().strip().split()])
	if arrn[i][0] > maxstn:
		maxstn = arrn[i][0]
	if arrn[i][1] < minendn:
		minendn = arrn[i][1]
m = int(input())
for i in range(m):
	arrm.append([int(x) for x in input().strip().split()])
	if arrm[i][0] > maxstm:
		maxstm = arrm[i][0]
	if arrm[i][1] < minendm:
		minendm = arrm[i][1]
ans = 0
if maxstn - minendm > ans:
	ans = maxstn - minendm
if maxstm - minendn > ans:
	ans = maxstm - minendn
print(ans)


def main():
	n = int(input())
	l1 = [0] * n
	r1 = [0] * n
	for i in range(0, n):
		(l1[i], r1[i]) = map(int, input().split())
	m = int(input())
	l2 = [0] * m
	r2 = [0] * m
	for i in range(0, m):
		(l2[i], r2[i]) = map(int, input().split())
	a = max(max(l1) - min(r2), max(l2) - min(r1))
	print(max(a, 0))
main()


n = int(input())
a = 0
b = 1000000000
for i in range(n):
	(l, k) = map(int, input().split())
	if a < l:
		a = l
	if k < b:
		b = k
m = int(input())
c = 0
d = 1000000000
for i in range(m):
	(l, k) = map(int, input().split())
	if c < l:
		c = l
	if k < d:
		d = k
z = max(c - b, a - d)
if z > 0:
	print(z)
else:
	print('0')


import sys
import re
input = lambda : sys.stdin.readline()
import functools

@functools.lru_cache(maxsize=10000)
def Main():
	n = int(input())
	mnr1 = mnr2 = 123456789123
	mxl1 = mxl2 = -123456789123
	for _ in range(n):
		(l, r) = map(int, input().split())
		mnr1 = min(mnr1, r)
		mxl1 = max(mxl1, l)
	ans = 0
	m = int(input())
	for _ in range(m):
		(l, r) = map(int, input().split())
		mnr2 = min(mnr2, r)
		mxl2 = max(mxl2, l)
	print(max(max(mxl2 - mnr1, mxl1 - mnr2), 0))
Main()


n = int(input().split()[0])
n0 = []
n1 = []
for i in range(n):
	p = input().split()
	n0.append(int(p[0]))
	n1.append(int(p[1]))
m = int(input().split()[0])
m0 = []
m1 = []
for i in range(m):
	l = input().split()
	m0.append(int(l[0]))
	m1.append(int(l[1]))
l = max(m0) - min(n1)
p = max(n0) - min(m1)
k = max(l, p)
if k <= 0:
	print('0')
else:
	print(k)


n = int(input())
ch_l = []
ch_r = []
for _ in range(n):
	(l, r) = map(int, input().split())
	ch_l.append(l)
	ch_r.append(r)
m = int(input())
co_l = []
co_r = []
for _ in range(m):
	(l, r) = map(int, input().split())
	co_l.append(l)
	co_r.append(r)
ch_l.sort()
ch_r.sort()
co_l.sort()
co_r.sort()
result = max(co_l[m - 1] - ch_r[0], ch_l[n - 1] - co_r[0])
if result > 0:
	print(result)
else:
	print('0')


n = int(input())
refA = []
for i in range(n):
	refA.append([int(x) for x in input().split()])
m = int(input())
refB = []
for i in range(m):
	refB.append([int(x) for x in input().split()])
refA_early = sorted(refA, key=lambda x: x[1])
refA_late = sorted(refA, key=lambda x: x[0], reverse=True)
refB_early = sorted(refB, key=lambda x: x[1])
refB_late = sorted(refB, key=lambda x: x[0], reverse=True)
cand1 = refA_early[0][1]
cand2 = refB_late[0][0]
if cand2 - cand1 < 0:
	ans1 = 0
else:
	ans1 = cand2 - cand1
cand1 = refB_early[0][1]
cand2 = refA_late[0][0]
if cand2 - cand1 < 0:
	ans2 = 0
else:
	ans2 = cand2 - cand1
print(max(ans1, ans2))


from operator import itemgetter
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
m = int(input())
b = [list(map(int, input().split())) for i in range(m)]
am = min(a, key=itemgetter(1))[1]
ap = max(a, key=itemgetter(0))[0]
bm = min(b, key=itemgetter(1))[1]
bp = max(b, key=itemgetter(0))[0]
ab = max(ap - bm, 0)
ba = max(bp - am, 0)
print(max(ab, ba))


INF = 1234567890
maxLeft1 = maxLeft2 = -INF
minRight1 = minRight2 = INF
n = int(input())
for i in range(n):
	(left, right) = map(int, input().split())
	minRight1 = min(minRight1, right)
	maxLeft1 = max(maxLeft1, left)
m = int(input())
for i in range(m):
	(left, right) = map(int, input().split())
	minRight2 = min(minRight2, right)
	maxLeft2 = max(maxLeft2, left)
print(max(0, max(maxLeft2 - minRight1, maxLeft1 - minRight2)))


n = int(input())
(a1, a2, b1, b2) = (float('-inf'), float('inf'), float('-inf'), float('inf'))
for i in range(n):
	(x, y) = list(map(int, input().split()))
	if x > a1:
		a1 = x
	if y < a2:
		a2 = y
m = int(input())
for i in range(m):
	(x, y) = list(map(int, input().split()))
	if x > b1:
		b1 = x
	if y < b2:
		b2 = y
(p, q) = (a1 - b2, b1 - a2)
if p < 0:
	p = 0
if q < 0:
	q = 0
print(max(p, q))


n = int(input())
inicioA = []
fimA = []
inicioB = []
fimB = []
for i in range(n):
	(inicio, fim) = [int(i) for i in input().split()]
	inicioA.append(inicio)
	fimA.append(fim)
m = int(input())
for i in range(m):
	(inicio, fim) = [int(i) for i in input().split()]
	inicioB.append(inicio)
	fimB.append(fim)
inicioA.sort()
fimA.sort()
inicioB.sort()
fimB.sort()
maiorTempoEntreChessProg = inicioB[len(inicioB) - 1] - fimA[0]
maiorTempoEntreProgChess = inicioA[len(inicioA) - 1] - fimB[0]
print(max(maiorTempoEntreChessProg, max(maiorTempoEntreProgChess, 0)))


(l1, r1, l2, r2) = ([], [], [], [])
for _ in range(int(input())):
	i = input().split()
	l1.append(int(i[0]))
	r1.append(int(i[1]))
for _ in range(int(input())):
	j = input().split()
	l2.append(int(j[0]))
	r2.append(int(j[1]))
(m1, m2) = (max(l2) - min(r1), max(l1) - min(r2))
print(max(m1, m2) if max(m1, m2) > 0 else 0)


n = int(input())
l1 = []
r1 = []
for i in range(n):
	(l, r) = list(map(int, input().split()))
	l1.append(l)
	r1.append(r)
lp = max(l1)
rp = min(r1)
m = int(input())
l2 = []
r2 = []
for i in range(m):
	(l3, r3) = list(map(int, input().split()))
	l2.append(l3)
	r2.append(r3)
(x, y) = (max(l2), min(r2))
print(max(0, x - rp, lp - y))


n = int(input())
(amax, amx) = (0, 0)
bmin = bmn = 1234567890
for i in range(n):
	(a, b) = map(int, input().split())
	amax = max(amax, a)
	bmin = min(bmin, b)
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	amx = max(amx, a)
	bmn = min(bmn, b)
r = max(amx - bmin, amax - bmn)
print(max(r, 0))


x = int(input())
xst = []
xfin = []
for i in range(x):
	y = list(map(int, input().split()))
	xst += [y[0]]
	xfin += [y[1]]
y = int(input())
yst = []
yfin = []
for i in range(y):
	x = list(map(int, input().split()))
	yst += [x[0]]
	yfin += [x[1]]
s = [0]
mixfin = min(xfin)
mayst = max(yst)
miyfin = min(yfin)
maxst = max(xst)
if mayst >= mixfin:
	s += [mayst - mixfin]
if maxst >= miyfin:
	s += [maxst - miyfin]
print(max(s))


l1 = []
r1 = []
n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	l1.append(l)
	r1.append(r)
l2 = []
r2 = []
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	l2.append(l)
	r2.append(r)
l1.sort()
l2.sort()
r1.sort()
r2.sort()
if max(l2[m - 1] - r1[0], l1[n - 1] - r2[0]) > 0:
	print(max(l2[m - 1] - r1[0], l1[n - 1] - r2[0]))
else:
	print(0)


n = int(input())
list1 = []
list2 = []
for i in range(n):
	(l1, r1) = input().strip().split(' ')
	(l1, r1) = (int(l1), int(r1))
	list1.append((l1, r1))
	list2.append((r1, l1))
list1.sort()
list2.sort()
list3 = []
list4 = []
m = int(input())
for i in range(m):
	(l1, r1) = input().strip().split(' ')
	(l1, r1) = (int(l1), int(r1))
	list3.append((l1, r1))
	list4.append((r1, l1))
list3.sort()
list4.sort()
ans1 = list3[m - 1][0] - list2[0][0]
ans2 = list1[n - 1][0] - list4[0][0]
if ans1 <= 0 and ans2 <= 0:
	print(0)
else:
	print(max(ans1, ans2))


chess = []
prog = []
n = int(input().strip())
for i in range(n):
	chess.append([int(j) for j in input().split()])
m = int(input().strip())
for i in range(m):
	prog.append([int(j) for j in input().split()])
gap = [0]
end = min([i[1] for i in chess])
start = max([i[0] for i in prog])
gap.append(start - end)
end = min([i[1] for i in prog])
start = max([i[0] for i in chess])
gap.append(start - end)
print(max(gap))


n = int(input())
smin = 10 ** 9
smax = 0
for i in range(n):
	(l, r) = (int(i) for i in input().split())
	if r < smin:
		smin = r
	if l > smax:
		smax = l
m = int(input())
pmin = 10 ** 9
pmax = 0
for i in range(m):
	(l, r) = (int(i) for i in input().split())
	if r < pmin:
		pmin = r
	if l > pmax:
		pmax = l
print(max(smax - pmin, pmax - smin, 0))


lastEnd = 1000000000 + 1
lastEnd2 = 1000000000 + 1
lastStart = -1
lastStart2 = -1
for i in range(int(input())):
	(r1, r2) = input().split()
	if int(r2) < lastEnd:
		lastEnd = int(r2)
	if int(r1) > lastStart2:
		lastStart2 = int(r1)
for i in range(int(input())):
	(r1, r2) = input().split()
	if int(r1) > lastStart:
		lastStart = int(r1)
	if int(r2) < lastEnd2:
		lastEnd2 = int(r2)
firstDiff = 0
lastDiff = 0
if lastStart - lastEnd > 0:
	firstDiff = lastStart - lastEnd
if lastStart2 - lastEnd2 > 0:
	lastDiff = lastStart2 - lastEnd2
if firstDiff > lastDiff:
	print(firstDiff)
else:
	print(lastDiff)


inf = 1234567890
minR1 = minR2 = inf
maxL1 = maxL2 = -inf
for i in range(int(input())):
	(l, r) = map(int, input().split())
	maxL1 = max(maxL1, l)
	minR1 = min(minR1, r)
for i in range(int(input())):
	(l, r) = map(int, input().split())
	maxL2 = max(maxL2, l)
	minR2 = min(minR2, r)
maxRes = max(maxL1 - minR2, maxL2 - minR1)
maxRes = max(maxRes, 0)
print(maxRes)


n = int(input())
r1 = 1000000000
r2 = 1000000000
l1 = 1
l2 = 1
for i in range(n):
	(l, r) = [int(j) for j in input().split()]
	if l > l1:
		l1 = l
	if r < r1:
		r1 = r
m = int(input())
for i in range(m):
	(l, r) = [int(j) for j in input().split()]
	if l > l2:
		l2 = l
	if r < r2:
		r2 = r
min = 0
if l1 > r2:
	min = l1 - r2
if l2 - r1 > min:
	min = l2 - r1
print(min)


n = int(input())
MAX = 10000000000000
c = []
for i in range(n):
	c.append(list(map(int, input().split())))
p = []
m = int(input())
for i in range(m):
	p.append(list(map(int, input().split())))
maxval = 0
min2n = MAX
for i in range(n):
	if c[i][1] < min2n:
		min2n = c[i][1]
max1m = 0
for i in range(m):
	if p[i][0] > max1m:
		max1m = p[i][0]
if max1m - min2n > maxval:
	maxval = max1m - min2n
max1n = 0
for i in range(n):
	if c[i][0] > max1n:
		max1n = c[i][0]
min2m = MAX
for i in range(m):
	if p[i][1] < min2m:
		min2m = p[i][1]
if max1n - min2m > maxval:
	maxval = max1n - min2m
print(maxval)


(a, b, ax, bx) = ([], [], [], [])
for i in range(int(input())):
	(_1, n) = map(int, input().split())
	a.append(_1)
	ax.append(n)
for i in range(int(input())):
	(n, _1) = map(int, input().split())
	b.append(n)
	bx.append(_1)
(pa, pb) = (0, 0)
if max(b) - min(ax) > 0:
	pa = max(b) - min(ax)
if max(a) - min(bx) > 0:
	pb = max(a) - min(bx)
if pa >= pb:
	print(pa)
elif pb > pa:
	print(pb)
else:
	print(0)


import sys, heapq
n = int(sys.stdin.readline())
chess = []
for _ in range(n):
	(a, b) = map(int, sys.stdin.readline().split())
	chess.append((a, b))
m = int(sys.stdin.readline())
ps = []
for _ in range(m):
	(a, b) = map(int, sys.stdin.readline().split())
	ps.append((a, b))
chess.sort(key=lambda x: x[1])
ps.sort(key=lambda x: -1 * x[0])
ans1 = ps[0][0] - chess[0][1] if ps[0][0] - chess[0][1] >= 0 else 0
chess.sort(key=lambda x: -1 * x[0])
ps.sort(key=lambda x: x[1])
ans2 = chess[0][0] - ps[0][1] if chess[0][0] - ps[0][1] >= 0 else 0
print(max(ans1, ans2))


n = int(input())
m1 = 99999999999
m3 = 0
for _ in range(n):
	(a, b) = map(int, input().split())
	if b < m1:
		m1 = b
	if a > m3:
		m3 = a
m2 = 0
m4 = 99999999999
m = int(input())
for _ in range(m):
	(a, b) = map(int, input().split())
	if a > m2:
		m2 = a
	if b < m4:
		m4 = b
if m2 - m1 < 0 and m3 - m4 < 0:
	print(0)
else:
	print(max(m2 - m1, m3 - m4))


(nn, mm) = ([], [])
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if i == 0:
		nn.append((a, b))
		nn.append((a, b))
	elif b < nn[0][1]:
		nn[0] = (a, b)
	elif a > nn[1][0]:
		nn[1] = (a, b)
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	if i == 0:
		mm.append((a, b))
		mm.append((a, b))
	elif b < mm[0][1]:
		mm[0] = (a, b)
	elif a > mm[1][0]:
		mm[1] = (a, b)
ans = max(0, mm[1][0] - nn[0][1], nn[1][0] - mm[0][1])
print(ans)


n = int(input())
chess = [list(map(int, input().split())) for i in range(n)]
m = int(input())
prog = [list(map(int, input().split())) for j in range(m)]

def find_min(seq):
	return seq[1]
min_chess_end = min(chess, key=find_min)[1]
max_chess_start = max(chess)[0]
min_prog_end = min(prog, key=find_min)[1]
max_prog_start = max(prog)[0]
max_amplitude = max(max_chess_start - min_prog_end, max_prog_start - min_chess_end)
if max_amplitude <= 0:
	print(0)
else:
	print(max_amplitude)


n = int(input())
am = 1000000001
ab = 0
bm = 1000000001
bb = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if a > ab:
		ab = a
	if b < am:
		am = b
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	if a > bb:
		bb = a
	if b < bm:
		bm = b
print(max(max(0, ab - bm), max(0, bb - am)))


I = lambda : list(map(int, input().split()))
n = I()[0]
p = [I() for i in range(n)]
m = I()[0]
q = [I() for i in range(m)]
print(max(max([i[0] for i in p]) - min([i[1] for i in q]), max([i[0] for i in q]) - min([i[1] for i in p]), 0))


import sys
n = int(input())
a_left_max = b_left_max = 1
a_right_min = b_right_min = 1000000000
for i in range(n):
	(l, r) = map(int, input().split())
	if a_left_max < l:
		a_left_max = l
	if a_right_min > r:
		a_right_min = r
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	if b_left_max < l:
		b_left_max = l
	if b_right_min > r:
		b_right_min = r
count1 = b_left_max - a_right_min
count2 = a_left_max - b_right_min
print(max(0, max(count1, count2)))


from sys import stdin, stdout
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
n = ii1()
end1 = float('inf')
start1 = float('-inf')
for i in range(n):
	(a, b) = iia()
	end1 = min(end1, b)
	start1 = max(start1, a)
m = ii1()
end2 = float('inf')
start2 = float('-inf')
for i in range(m):
	(a, b) = iia()
	end2 = min(end2, b)
	start2 = max(start2, a)
print(max(start2 - end1, start1 - end2, 0))


n = int(input())
min_n = 10 ** 9
max_n = 1
min_m = 10 ** 9
max_m = 1
for i in range(n):
	(l, r) = map(int, input().split())
	if l > max_n:
		max_n = l
	if r < min_n:
		min_n = r
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	if r < min_m:
		min_m = r
	if l > max_m:
		max_m = l
if max(max_n - min_m, max_m - min_n) <= 0:
	print(0)
else:
	print(max(max_n - min_m, max_m - min_n))


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
m = int(input())
b = [list(map(int, input().split())) for j in range(m)]
print(max(0, max([b[j][0] for j in range(m)]) - min([a[i][1] for i in range(n)]), max([a[i][0] for i in range(n)]) - min([b[j][1] for j in range(m)])))


res = 0
res2 = 0
itog = 0
minl = 1000000000
minj = 0
maxl = 0
maxj = 1000000000
k = 0
n = int(input())
for i in range(0, n):
	s = input()
	lis = s.split(' ')
	l = int(lis[0])
	rl = int(lis[1])
	if rl < minl:
		minl = rl
	if l > maxl:
		maxl = l
m = int(input())
for i in range(0, m):
	s = input()
	lis2 = s.split(' ')
	j = int(lis2[0])
	rj = int(lis2[1])
	if j > minj:
		minj = j
	if rj < maxj:
		maxj = rj
res = minj - minl
res2 = maxl - maxj
if res > res2:
	itog = res
else:
	itog = res2
if k == m:
	itog = 0
if itog < 0:
	itog = 0
print(itog)


def main():
	QWE = 'insert'
	INF = 10 ** 9 + 9
	EPS = 10 ** (-10)
	import sys, math, re
	n = int(input())
	(mn1, mx1, mn2, mx2) = (INF, -INF, INF, -INF)
	for i in range(n):
		(l, r) = map(int, input().split(' ', 1))
		if l > mx1:
			mx1 = l
		if r < mn1:
			mn1 = r
	m = int(input())
	for i in range(m):
		(l, r) = map(int, input().split(' ', 1))
		if l > mx2:
			mx2 = l
		if r < mn2:
			mn2 = r
	rez = max(mx1 - mn2, mx2 - mn1, 0)
	print(rez)
main()


chess = [tuple(map(int, input().split())) for _ in range(int(input()))]
programming = [tuple(map(int, input().split())) for _ in range(int(input()))]
print(max(max(programming, key=lambda data: data[0])[0] - min(chess, key=lambda data: data[1])[1], max(chess, key=lambda data: data[0])[0] - min(programming, key=lambda data: data[1])[1], 0))


import math
import itertools

def ria():
	return [int(i) for i in input().split()]
mx = 0
sz = ria()[0]
mx1 = 0
mn1 = 2000000000
for i in range(sz):
	(l, r) = ria()
	mx1 = max(l, mx1)
	mn1 = min(r, mn1)
sz = ria()[0]
mx2 = 0
mn2 = 2000000000
for i in range(sz):
	(l, r) = ria()
	mx2 = max(l, mx2)
	mn2 = min(r, mn2)
mx = max(mx, mx1 - mn2)
mx = max(mx, mx2 - mn1)
print(mx)


n1 = int(input())
(start1, end1) = list(map(int, input().split()))
n1 -= 1
for _ in range(n1):
	(s1, e1) = list(map(int, input().split()))
	if s1 > start1:
		start1 = s1
	if e1 < end1:
		end1 = e1
n2 = int(input())
(start2, end2) = list(map(int, input().split()))
n2 -= 1
for _ in range(n2):
	(s2, e2) = list(map(int, input().split()))
	if s2 > start2:
		start2 = s2
	if e2 < end2:
		end2 = e2
gap = max(0, start2 - end1, start1 - end2)
print(gap)


def getSmallest(alist):
	min = alist[0]
	for time in alist:
		if min > time:
			min = time
	return min

def getLargest(alist):
	max = alist[0]
	for time in alist:
		if max < time:
			max = time
	return max
n = int(input())
chessStart = []
chessEnd = []
for i in range(n):
	nList = input().split()
	chessStart.append(int(nList[0]))
	chessEnd.append(int(nList[1]))
m = int(input())
progStart = []
progEnd = []
for i in range(m):
	mList = input().split()
	progStart.append(int(mList[0]))
	progEnd.append(int(mList[1]))
breakA = getLargest(chessStart) - getSmallest(progEnd)
breakB = getLargest(progStart) - getSmallest(chessEnd)
if breakA <= 0 and breakB <= 0:
	print(0)
elif breakA > breakB:
	print(breakA)
else:
	print(breakB)


i = int(input())
a = [list(map(int, input().split())) for _ in range(i)]
i = int(input())
b = [list(map(int, input().split())) for _ in range(i)]
mi2a = min([x[1] for x in a])
mi2b = min([x[1] for x in b])
ma1a = max([x[0] for x in a])
ma1b = max([x[0] for x in b])
if ma1a - mi2b > ma1b - mi2a:
	print(ma1a - mi2b if ma1a - mi2b > 0 else 0)
else:
	print(ma1b - mi2a if ma1b - mi2a > 0 else 0)


from math import inf, sqrt, floor, ceil
from collections import Counter, defaultdict, deque
from heapq import heappush as hpush, heappop as hpop, heapify as h
from operator import itemgetter
from itertools import product
from bisect import bisect_left, bisect_right

def f():
	(x, y) = (inf, -1)
	for i in range(int(input())):
		v = input().split()
		x = min(x, int(v[1]))
		y = max(y, int(v[0]))
	return (x, y)
(x1min, y1max) = f()
(x2min, y2max) = f()
print(max(0, y2max - x1min, y1max - x2min))


n = int(input())
al = []
ar = []
bl = []
br = []
ans = 0
for i in range(n):
	(x, y) = map(int, input().split())
	al.append(x)
	ar.append(y)
m = int(input())
for i in range(m):
	(x, y) = map(int, input().split())
	bl.append(x)
	br.append(y)
ans = max(0, max(max(al) - min(br), max(bl) - min(ar)))
print(ans)


from sys import maxsize, stdout, stdin, stderr
tup = lambda : map(int, stdin.readline().split())
I = lambda : int(stdin.readline())
lint = lambda : [int(x) for x in stdin.readline().split()]
S = lambda : stdin.readline().replace('\n', '').strip()

def debug(*args, c=6):
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=stderr)
stpr = lambda x: stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
from collections import defaultdict, Counter
from math import gcd
from bisect import bisect_left
from math import floor, ceil
(ma, mi) = (-1, maxsize)
for _ in range(I()):
	(x, y) = tup()
	ma = max(x, ma)
	mi = min(mi, y)
ans = 0
for i in range(I()):
	(x, y) = tup()
	ans = max(ans, x - mi, ma - y)
print(ans)


MAX = 2147483647
n = int(input())
min_n = MAX
max_n = 0
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	min_n = min(min_n, b)
	max_n = max(max_n, a)
min_m = MAX
max_m = 0
m = int(input())
for i in range(m):
	(a, b) = [int(x) for x in input().split()]
	min_m = min(min_m, b)
	max_m = max(max_m, a)
res = max(max(max_m - min_n, 0), max(max_n - min_m, 0))
print(res)


infinity = 1234567890
minR1 = minR2 = infinity
maxL1 = maxL2 = -infinity
n = int(input())
for i in range(0, n):
	(l, r) = map(int, input().split())
	maxL1 = max(maxL1, l)
	minR1 = min(minR1, r)
m = int(input())
for i in range(0, m):
	(l, r) = map(int, input().split())
	maxL2 = max(maxL2, l)
	minR2 = min(minR2, r)
res = max(maxL2 - minR1, maxL1 - minR2)
print(max(res, 0))


from math import inf

def min_max():
	n_classes = int(input())
	earlist_end = inf
	latest_start = -inf
	for n in range(n_classes):
		interval = list(map(lambda x: int(x), input().split()))
		if interval[1] < earlist_end:
			earlist_end = interval[1]
		if interval[0] > latest_start:
			latest_start = interval[0]
	return [latest_start, earlist_end]
chess_classes = min_max()
programming_classes = min_max()
chess_class_first = programming_classes[0] - chess_classes[1]
programming_class_first = chess_classes[0] - programming_classes[1]
if chess_class_first < 0 and programming_class_first < 0:
	print(0)
elif chess_class_first < 0:
	print(programming_class_first)
elif programming_class_first < 0:
	print(chess_class_first)
else:
	result = chess_class_first if chess_class_first > programming_class_first else programming_class_first
	print(result)


n = int(input())
a = []
for _ in range(n):
	(l, r) = list(map(int, input().split()))
	a.append([l, r])
m = int(input())
b = []
for _ in range(m):
	(l, r) = list(map(int, input().split()))
	b.append([l, r])
b.sort()
res = 0
for i in a:
	res = max(b[m - 1][0] - i[1], res)
a.sort()
for i in b:
	res = max(a[n - 1][0] - i[1], res)
print(res)


n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]
m = int(input())
b = [[int(x) for x in input().split()] for _ in range(m)]
ans = 0
(R, L) = (1000000000.0, 0)
for i in range(n):
	R = min(R, a[i][1])
for i in range(m):
	L = max(L, b[i][0])
ans = max(ans, L - R)
(R, L) = (1000000000.0, 0)
for i in range(m):
	R = min(R, b[i][1])
for i in range(n):
	L = max(L, a[i][0])
ans = max(ans, L - R)
print(ans)


from sys import stdin, stdout

def is_separated(a, b):
	if a[1] < b[0]:
		return 2
	elif a[0] > b[1]:
		return 1
	else:
		return 0

def calc_rest_time(a, b):
	return min(b) - max(a)

def solve(chess, computer):
	max_time = 0
	for chess_schedule in chess:
		for computer_schedule in computer:
			difference = is_separated(chess_schedule, computer_schedule)
			if difference == 1:
				time = calc_rest_time(computer_schedule, chess_schedule)
				max_time = max(time, max_time)
			elif difference == 2:
				time = calc_rest_time(chess_schedule, computer_schedule)
				max_time = max(time, max_time)
	return max_time

def get_extremes(lst):
	min_left = 0
	max_right = 0
	min_left_value = float('inf')
	max_right_value = 0
	for e in lst:
		if min_left_value > e[1]:
			min_left_value = e[1]
			min_left = e
		if max_right_value < e[0]:
			max_right_value = e[0]
			max_right = e
	return (min_left, max_right)

def solve2(chess, computer):
	(min_chess, max_chess) = get_extremes(chess)
	(min_computer, max_computer) = get_extremes(computer)
	option1_time = 0
	option2_time = 0
	if is_separated(min_chess, max_computer) == 2:
		option1_time = calc_rest_time(min_chess, max_computer)
	if is_separated(min_computer, max_chess) == 2:
		option2_time = calc_rest_time(min_computer, max_chess)
	return max(option1_time, option2_time)
chess = []
n = int(stdin.readline())
for i in range(n):
	(a, b) = map(int, input().split())
	chess.append((a, b))
computer = []
m = int(stdin.readline())
for i in range(m):
	(a, b) = map(int, input().split())
	computer.append((a, b))
solution = solve2(chess, computer)
stdout.write(str(solution))


n = int(input())
q = []
e = []
for i in range(n):
	(*t,) = map(int, input().split())
	q += [t[1]]
	e += [t[0]]
q = min(q)
e = max(e)
m = int(input())
w = []
r = []
for i in range(m):
	(*t,) = map(int, input().split())
	w += [t[0]]
	r += [t[1]]
w = max(w)
r = min(r)
if e - r > w - q:
	w = e
	q = r
if w - q < 0:
	print(0)
else:
	print(w - q)


n = int(input())
p = [0, 10 ** 10]
q = [0, 10 ** 10]
for i in range(n):
	(a, b) = map(int, input().split())
	p[0] = max(p[0], a)
	p[1] = min(p[1], b)
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	q[0] = max(q[0], a)
	q[1] = min(q[1], b)
print(max(0, q[0] - p[1], p[0] - q[1]))


n = int(input())
ln = sorted((list(map(int, input().split())) for _ in range(n)))
m = int(input())
lm = sorted((list(map(int, input().split())) for _ in range(m)))
lln = sorted((x[::-1] for x in ln))
llm = sorted((x[::-1] for x in lm))
ans = ln[-1][0] - llm[0][0]
if lm[-1][0] - lln[0][0] > ans:
	ans = lm[-1][0] - lln[0][0]
print(max(0, ans))


(mir1, mir2) = (10000000000, 10000000000)
(mal1, mal2) = (-1000000000, -1000000000)
n = int(input())
for i in range(n):
	(l, r) = map(int, input().split())
	mal1 = max(mal1, l)
	mir1 = min(mir1, r)
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	mal2 = max(mal2, l)
	mir2 = min(mir2, r)
print(max(max(mal1 - mir2, mal2 - mir1), 0))


segment1left = (10 ** 9 + 1, 10 ** 9 + 2)
segment1right = (-2, -1)
segment2left = (10 ** 9 + 1, 10 ** 9 + 2)
segment2right = (-2, -1)
n = int(input())
for __ in range(n):
	(l, r) = list(map(int, input().split()))
	if segment1left[1] > r:
		segment1left = (l, r)
	if segment1right[0] < l:
		segment1right = (l, r)
m = int(input())
for __ in range(m):
	(l, r) = list(map(int, input().split()))
	if segment2left[1] > r:
		segment2left = (l, r)
	if segment2right[0] < l:
		segment2right = (l, r)
out = 0
if segment1left[1] < segment2right[0] and segment1left != (10 ** 9 + 1, 10 ** 9 + 2) and (segment2right != (-2, -1)):
	out = abs(segment1left[1] - segment2right[0])
if segment2left[1] < segment1right[0] and segment2left != (10 ** 9 + 1, 10 ** 9 + 2) and (segment1right != (-2, -1)):
	out = max(out, abs(segment2left[1] - segment1right[0]))
print(out)


l_c = list()
for _ in range(int(input())):
	l_c.append(list(map(int, input().split())))
l_p = list()
for _ in range(int(input())):
	l_p.append(list(map(int, input().split())))
max_c = 1
min_c = None
for c in l_c:
	max_c = max(max_c, c[0])
	if min_c == None:
		min_c = c[1]
	else:
		min_c = min(min_c, c[1])
max_p = 1
min_p = None
for p in l_p:
	max_p = max(max_p, p[0])
	if min_p == None:
		min_p = p[1]
	else:
		min_p = min(min_p, p[1])
print(max(0, max_p - min_c, max_c - min_p))


n = int(input())
(s, s1) = ([], [])
(x, y) = (100000000000, -1)
for i in range(n):
	(a, b) = map(int, input().split())
	x = min(x, b)
	y = max(y, a)
m = int(input())
(x1, y1) = (100000000000, -1)
for j in range(m):
	(a, b) = map(int, input().split())
	x1 = min(x1, b)
	y1 = max(y1, a)
print(max(0, y1 - x, y - x1))


def main():
	n = int(input())
	(mnrn, mxln) = (1000000000, 0)
	for i in range(n):
		(l, r) = [int(x) for x in input().split()]
		mnrn = min(mnrn, r)
		mxln = max(mxln, l)
	m = int(input())
	(mnrm, mxlm) = (1000000000, 0)
	for i in range(m):
		(l, r) = [int(x) for x in input().split()]
		mnrm = min(mnrm, r)
		mxlm = max(mxlm, l)
	d1 = mxlm - mnrn if mxlm > mnrn else 0
	d2 = mxln - mnrm if mxln > mnrm else 0
	ans = max(d1, d2)
	print(ans)
main()


def f():
	n = int(input())
	mb = 1
	me = 10 ** 9
	for _ in range(n):
		(b, e) = [int(i) for i in input().split()]
		mb = max(mb, b)
		me = min(me, e)
	return (mb, me)
(cb, ce) = f()
(pb, pe) = f()
a1 = pb - ce
a2 = cb - pe
ans = max(a1, a2)
ans = max(ans, 0)
print(ans)


nc = int(input())
chls = []
for i in range(nc):
	lis = [int(x) for x in input().split()]
	chls.append(lis)
np = int(input())
prls = []
for j in range(np):
	lis = [int(x) for x in input().split()]
	prls.append(lis)
(min_ch, max_ch, min_pr, max_pr) = (10 ** 9, 0, 10 ** 9, 0)
for i in range(nc):
	min_ch = min(min_ch, chls[i][1])
	max_ch = max(max_ch, chls[i][0])
for j in range(np):
	min_pr = min(min_pr, prls[j][1])
	max_pr = max(max_pr, prls[j][0])
c = max(max_pr - min_ch, max_ch - min_pr)
if c < 0:
	print(0)
else:
	print(c)


(chess, programming) = ([], [])
for _ in range(int(input().strip())):
	(l, r) = map(int, input().strip().split())
	chess.append((l, r))
for _ in range(int(input().strip())):
	(l, r) = map(int, input().strip().split())
	programming.append((l, r))
ans1 = max(programming, key=lambda x: x[0])[0] - min(chess, key=lambda x: x[1])[1]
ans2 = max(chess, key=lambda x: x[0])[0] - min(programming, key=lambda x: x[1])[1]
print(max(0, max(ans1, ans2)))


from sys import stdin
(max1, max2, min1, min2) = (0, 0, 10 ** 9 + 1, 10 ** 9 + 1)
n = int(input())
for i in range(n):
	x = list(map(int, stdin.readline().split()))
	if max1 < x[0]:
		max1 = x[0]
	if min1 > x[1]:
		min1 = x[1]
n = int(input())
for i in range(n):
	x = list(map(int, stdin.readline().split()))
	if max2 < x[0]:
		max2 = x[0]
	if min2 > x[1]:
		min2 = x[1]
x = max(0, max(max2 - min1, max1 - min2))
print(x)


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
m = int(input())
b = [list(map(int, input().split())) for _ in range(m)]
maxL = max([x[0] for x in a])
minR = min([x[1] for x in a])
ans = 0
for x in b:
	ans = max([ans, maxL - x[1], x[0] - minR])
print(ans)


ma1 = -1
mi1 = 9999999999
ma = -1
mi = 9999999999
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if b < mi1:
		mi1 = b
	if a > ma:
		ma = a
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if a > ma1:
		ma1 = a
	if b < mi:
		mi = b
d = ma - mi
e = ma1 - mi1
print(max(0, d, e))


n = int(input())
chess = []
for _ in range(n):
	a = list(map(int, input().split()))
	chess.append(a)
m = int(input())
prog = []
for _ in range(m):
	a = list(map(int, input().split()))
	prog.append(a)
(min_chess, max_chess, min_prog, max_prog) = (10 ** 9, 0, 10 ** 9, 0)
for i in range(n):
	min_chess = min(min_chess, chess[i][1])
	max_chess = max(max_chess, chess[i][0])
for i in range(m):
	min_prog = min(min_prog, prog[i][1])
	max_prog = max(max_prog, prog[i][0])
c = max(max_prog - min_chess, max_chess - min_prog)
if c < 0:
	print(0)
else:
	print(c)


n = int(input())
A1 = []
A2 = []
A3 = []
A4 = []
(l1, r1) = (1000000000, 0)
(l2, r2) = (1000000000, 0)
for i in range(n):
	(a, b) = map(int, input().split())
	if b < l1:
		l1 = b
		A1 = [a, b]
	if a > r1:
		r1 = a
		A2 = [a, b]
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	if b < l2:
		l2 = b
		A3 = [a, b]
	if a > r2:
		r2 = a
		A4 = [a, b]
(x, y) = (-1, -1)
if A1 != [] and A4 != []:
	x = A4[0] - A1[1]
if A2 != [] and A3 != []:
	y = A2[0] - A3[1]
if x > 0 and x > y:
	print(x)
elif y > 0 and y > x:
	print(y)
else:
	print(0)


import sys
import itertools
import collections

def rs(x=''):
	return sys.stdin.readline().strip() if len(x) == 0 else input(x).strip()

def ri(x=''):
	return int(rs(x))

def rm(x=''):
	return map(str, rs(x).split())

def rl(x=''):
	return rs(x).split()

def rmi(x=''):
	return map(int, rs(x).split())

def rli(x=''):
	return [int(x) for x in rs(x).split()]

def println(val):
	sys.stdout.write(str(val) + '\n')

def solve(testCase):
	n = ri()
	chessClasses = [tuple(rmi()) for _ in range(n)]
	m = ri()
	programmingClasses = [tuple(rmi()) for _ in range(m)]
	mx1 = mx2 = 0
	mn1 = mn2 = 10 ** 69
	for (x, y) in chessClasses:
		mn1 = min(mn1, y)
		mx1 = max(mx1, x)
	for (x, y) in programmingClasses:
		mn2 = min(mn2, y)
		mx2 = max(mx2, x)
	print(max(mx2 - mn1, mx1 - mn2, 0))
solve(1)


n = int(input())
mn1 = 1000000100
mx1 = 0
for i in range(n):
	(l, r) = map(int, input().split())
	mn1 = min(mn1, r)
	mx1 = max(mx1, l)
m = int(input())
mn2 = 1000000100
mx2 = 0
for i in range(m):
	(l, r) = map(int, input().split())
	mn2 = min(mn2, r)
	mx2 = max(mx2, l)
print(max(0, max(mx2 - mn1, mx1 - mn2)))


n = int(input())
chess = [[], []]
for x in range(n):
	string = input()
	numbers = string.split()
	chess[0].append(int(numbers[0]))
	chess[1].append(int(numbers[1]))
n = int(input())
programming = [[], []]
for x in range(n):
	string = input()
	numbers = string.split()
	programming[0].append(int(numbers[0]))
	programming[1].append(int(numbers[1]))
p = max(chess[0])
q = min(programming[1])
r = max(programming[0])
s = min(chess[1])
a = p - q
b = r - s
if a < 0:
	a = 0
if b < 0:
	b = 0
print(max([a, b]))


n = int(input())
a = b = i = 0
maxstart1 = 0
maxstart2 = 0
minend1 = 1000000001
minend2 = 1000000001
while i < n:
	(a, b) = map(int, input().split())
	if a > maxstart1:
		maxstart1 = a
	if b < minend1:
		minend1 = b
	i += 1
i = 0
k = int(input())
while i < k:
	(a, b) = map(int, input().split())
	if a > maxstart2:
		maxstart2 = a
	if b < minend2:
		minend2 = b
	i += 1
z1 = maxstart1 - minend2
z2 = maxstart2 - minend1
if z1 > z2 and z1 >= 0:
	print(z1)
elif z1 <= z2 and z2 >= 0:
	print(z2)
else:
	print(0)


(mx, max_start, min_end) = (0, 0, int(10000000000.0))
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	(min_end, max_start) = (min(min_end, b), max(max_start, a))
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	mx = max(mx, max(a - min_end, max_start - b))
print(mx)


n = int(input())
l1max = -1
r1min = 10 ** 9 + 5
for _ in range(n):
	(l, r) = map(int, input().split(' '))
	l1max = max(l, l1max)
	r1min = min(r, r1min)
m = int(input())
l2max = -1
r2min = 10 ** 9 + 5
for _ in range(m):
	(l, r) = map(int, input().split(' '))
	l2max = max(l, l2max)
	r2min = min(r, r2min)
print(max(0, l1max - r2min, l2max - r1min))


n = int(input())
lc = 0
rc = 10 ** 9 + 1
for i in range(n):
	(l, r) = map(int, input().split())
	lc = max(l, lc)
	rc = min(r, rc)
m = int(input())
lp = 0
rp = 10 ** 9 + 1
for i in range(m):
	(l, r) = map(int, input().split())
	lp = max(l, lp)
	rp = min(r, rp)
print(max(0, lp - rc, lc - rp))


n = int(input())
a = [0, 10 ** 10, 0, 10 ** 10]
for i in range(n):
	(x, y) = map(int, input().split())
	a[0] = max(a[0], x)
	a[1] = min(a[1], y)
m = int(input())
b = [0, 10 ** 10, 0, 10 ** 10]
for i in range(m):
	(x, y) = map(int, input().split())
	b[0] = max(b[0], x)
	b[1] = min(b[1], y)
print(max(0, a[0] - b[1], b[0] - a[1]))


n = int(input())
(mia, maa) = (-1, -1)
for q in range(n):
	(x, y) = map(int, input().split())
	if mia == -1:
		mia = y
		maa = x
	else:
		mia = min(mia, y)
		maa = max(maa, x)
m = int(input())
(mib, mab) = (-1, -1)
for q in range(m):
	(x, y) = map(int, input().split())
	if mib == -1:
		mib = y
		mab = x
	else:
		mib = min(mib, y)
		mab = max(mab, x)
ans = max(mab - mia, maa - mib)
if ans > 0:
	print(ans)
else:
	print(0)


nmin = 9999999999
nmax = -1
mmin = 9999999999
mmax = -1
for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if a > nmax:
		nmax = a
	if b < nmin:
		nmin = b
for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if a > mmax:
		mmax = a
	if b < mmin:
		mmin = b
ans = max(mmax - nmin, nmax - mmin)
if ans <= 0:
	print(0)
else:
	print(ans)


n = int(input())
max1 = 0
min1 = 10 ** 9
for i in range(n):
	(l, r) = map(int, input().split())
	max1 = max(max1, l)
	min1 = min(min1, r)
m = int(input())
max2 = 0
min2 = 10 ** 9
for i in range(m):
	(l, r) = map(int, input().split())
	max2 = max(max2, l)
	min2 = min(min2, r)
print(max(max2 - min1, max1 - min2, 0))


n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
m = int(input())
b = []
for i in range(m):
	b.append(list(map(int, input().split())))
a.sort()
b1 = b[:]
b.sort()
b1.sort(key=lambda x: x[1])
ans = 0
for i in a:
	ans = max(ans, b[-1][0] - i[1])
	ans = max(ans, i[0] - b1[0][1])
print(ans)


import sys
input = sys.stdin.readline
a = []
b = []
c = []
d = []
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	c.append(x)
	d.append(y)
ans = max(0, max(c) - min(b))
print(max(ans, max(a) - min(d)))


def get():
	n = int(input())
	(a, b) = (float('inf'), -1)
	for _ in range(n):
		x = input().split()
		a = min(a, int(x[1]))
		b = max(b, int(x[0]))
	return (a, b)
(a, b) = get()
(c, d) = get()
print(max(0, max(d - a, b - c)))


__author__ = 'zihaozhu'
from sys import stdin

def intersect(tup1, tup2):
	if tup1[0] >= tup2[0] and tup1[0] <= tup2[1]:
		return True
	elif tup1[1] >= tup2[0] and tup1[1] <= tup2[1]:
		return True
	elif tup2[0] >= tup1[0] and tup2[0] <= tup1[1]:
		return True
	elif tup2[1] >= tup1[1] and tup2[1] <= tup1[1]:
		return True
	return False

def findMin(tup1, tup2):
	ans = min(abs(tup1[0] - tup2[0]), abs(tup1[1] - tup2[0]))
	ans = min(ans, min(abs(tup1[0] - tup2[1]), abs(tup1[1] - tup2[1])))
	return ans
chessnum = int(stdin.readline())
answer = 0
r1 = float('inf')
l1 = -float('inf')
r2 = float('inf')
l2 = -float('inf')
chess = list()
for i in range(chessnum):
	temp = tuple(map(int, stdin.readline().split()))
	r1 = min(temp[1], r1)
	l1 = max(temp[0], l1)
programmingnum = int(stdin.readline())
for j in range(programmingnum):
	temp = tuple(map(int, stdin.readline().split()))
	r2 = min(temp[1], r2)
	l2 = max(temp[0], l2)
print(max(0, max(l2 - r1, l1 - r2)))


n = int(input())
chess = list()
for i in range(n):
	(a, b) = list(map(int, input().split()))
	chess.append([a, b])
m = int(input())
pro = list()
for i in range(m):
	(a, b) = list(map(int, input().split()))
	pro.append([a, b])
(l1, e1, l2, e2) = (0, 1000000000, 0, 1000000000)
for i in range(n):
	l1 = max(chess[i][0], l1)
	e1 = min(chess[i][1], e1)
for i in range(m):
	l2 = max(pro[i][0], l2)
	e2 = min(pro[i][1], e2)
print(max([0, l2 - e1, l1 - e2]))


l1 = 0
r1 = 10 ** 9
for i in range(int(input())):
	(l, r) = map(int, input().split())
	l1 = max(l, l1)
	r1 = min(r, r1)
l2 = 0
r2 = 10 ** 9
for i in range(int(input())):
	(l, r) = map(int, input().split())
	l2 = max(l, l2)
	r2 = min(r, r2)
print(max(0, l2 - r1, l1 - r2))


from operator import itemgetter
n = int(input())
ln = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	ln.append((a, b))
ln = sorted(ln, key=itemgetter(1))
m = int(input())
lm = []
for k in range(m):
	(a, b) = list(map(int, input().split()))
	lm.append((a, b))
lm = sorted(lm, key=itemgetter(0))
dif = 0
dif = lm[m - 1][0] - ln[0][1]
if dif < 0:
	dif = 0
ln = sorted(ln, key=itemgetter(0))
lm = sorted(lm, key=itemgetter(1))
ned = ln[n - 1][0] - lm[0][1]
if ned > dif:
	dif = ned
print(dif)


def main():
	n = int(input())
	(chess_l, chess_r) = ([], [])
	for i in range(n):
		(l, r) = map(int, input().split())
		chess_l.append(l)
		chess_r.append(r)
	m = int(input())
	(prog_l, prog_r) = ([], [])
	for i in range(m):
		(l, r) = map(int, input().split())
		prog_l.append(l)
		prog_r.append(r)
	res = max(0, max(prog_l) - min(chess_r), max(chess_l) - min(prog_r))
	print(res)
main()


def minimum(list):
	minn = list[0]
	for x in range(1, len(list)):
		if list[x] < minn:
			minn = list[x]
	return minn

def maximum(list):
	maxx = list[0]
	for x in range(1, len(list)):
		if list[x] > maxx:
			maxx = list[x]
	return maxx
chess_classes = int(input())
chess_period_end = []
chess_period_start = []
for classes in range(chess_classes):
	(period_start, period_end) = input().split()
	chess_period_end.append(int(period_end))
	chess_period_start.append(int(period_start))
prog_classes = int(input())
prog_period_start = []
prog_period_end = []
for classes in range(prog_classes):
	(period_start, period_end) = input().split()
	prog_period_start.append(int(period_start))
	prog_period_end.append(int(period_end))
min1 = minimum(chess_period_end)
max1 = maximum(prog_period_start)
result1 = max1 - min1
min2 = minimum(prog_period_end)
max2 = maximum(chess_period_start)
result2 = max2 - min2
if result1 < 1 and result2 < 1:
	print('0')
elif result1 > result2:
	print(result1)
else:
	print(result2)


n = int(input())
(l1, l2, l3, l4) = ([], [], [], [])
for i in range(n):
	(a, b) = map(int, input().split())
	l1.append(a)
	l2.append(b)
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	l3.append(a)
	l4.append(b)
(m1, m2, m3, m4) = (max(l1), min(l2), max(l3), min(l4))
x = max(m3 - m2, m1 - m4)
print(max(0, x))


n = int(input())
mr = 10 ** 10
ml2 = 0
for _ in range(n):
	(a, b) = map(int, input().split())
	mr = min(mr, b)
	ml2 = max(ml2, a)
ml = 0
mr2 = 10 ** 10
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	ml = max(ml, a)
	mr2 = min(mr2, b)
print(max(0, ml - mr, ml2 - mr2))


n = int(input())
aa = []
bb = []
for _ in range(n):
	aa.append(list(map(int, input().split())))
m = int(input())
for _ in range(m):
	bb.append(list(map(int, input().split())))
x = min(aa, key=lambda x: x[1])
y = max(bb, key=lambda x: x[0])
mi = max(y[0] - x[1], 0)
x = min(bb, key=lambda x: x[1])
y = max(aa, key=lambda x: x[0])
mi = max(mi, max(y[0] - x[1], 0))
print(mi)


a = 0
b = 10 ** 10
c = 0
d = 10 ** 10
for _ in range(int(input())):
	(e, f) = map(int, input().split())
	if e > a:
		a = e
	if f < b:
		b = f
for _ in range(int(input())):
	(e, f) = map(int, input().split())
	if e > c:
		c = e
	if f < d:
		d = f
print(max(c - b, a - d, 0))


n = int(input())
la = [-1] * n
ra = [-1] * n
for i in range(n):
	(la[i], ra[i]) = map(int, input().split(' '))
m = int(input())
lb = [-1] * m
rb = [-1] * m
for i in range(m):
	(lb[i], rb[i]) = map(int, input().split(' '))
best = 0
pa = la[0]
qa = ra[0]
for i in range(n):
	if la[i] > pa:
		pa = la[i]
	if ra[i] < qa:
		qa = ra[i]
for j in range(m):
	pb = lb[j]
	qb = rb[j]
	if pb - qa > best:
		best = pb - qa
	if pa - qb > best:
		best = pa - qb
print(best)


def lk(n):
	(lk1, lk2) = map(int, input().split())
	(ln1, ln2) = (lk1, lk2)
	for i in range(n - 1):
		(x, y) = map(int, input().split())
		if y < lk2:
			lk1 = x
			lk2 = y
		if x > ln1:
			ln1 = x
			ln2 = y
	return (lk1, lk2, ln1, ln2)

def maxi():
	if lnm1 - lkn2 >= lnn1 - lkm2 and lnm1 - lkn2 > 0:
		return lnm1 - lkn2
	elif lnn1 - lkm2 > 0:
		return lnn1 - lkm2
	return 0
n = int(input())
(lkn1, lkn2, lnn1, lnn2) = lk(n)
m = int(input())
(lkm1, lkm2, lnm1, lnm2) = lk(m)
print(maxi())


n = int(input())
A1 = []
A2 = []
A3 = []
A4 = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	A1.append(a)
	A2.append(b)
m = int(input())
for i in range(m):
	(a, b) = list(map(int, input().split()))
	A3.append(a)
	A4.append(b)
x = min(A2)
y = max(A3)
z = max(0, y - x)
x1 = min(A4)
y1 = max(A1)
z1 = max(0, y1 - x1)
print(max(z, z1))


n = int(input().strip())
mina = list()
minb = list()
minc = list()
mind = list()
for i in range(n):
	(a, b) = map(int, input().strip().split())
	mina.append(a)
	minb.append(b)
m = int(input().strip())
for i in range(m):
	(c, d) = map(int, input().strip().split())
	minc.append(c)
	mind.append(d)
print(max((max(mina) - min(mind), max(minc) - min(minb), 0)))


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
import time
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string
start_time = time.time()

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def getMat(n):
	return [getInts() for _ in range(n)]
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	LR1 = getMat(N)
	M = getInt()
	LR2 = getMat(M)
	(min_end1, max_start1) = (10 ** 9 + 1, 0)
	for (l, r) in LR1:
		min_end1 = min(min_end1, r)
		max_start1 = max(max_start1, l)
	(min_end2, max_start2) = (10 ** 9 + 1, 0)
	for (l, r) in LR2:
		min_end2 = min(min_end2, r)
		max_start2 = max(max_start2, l)
	return max(max_start1 - min_end2, max_start2 - min_end1, 0)
print(solve())


n = int(input())
a = 0
b = 10 ** 9
c = 0
d = 10 ** 9
for i in range(n):
	(x, y) = map(int, input().split(' '))
	if x > a:
		a = x
	if y < b:
		b = y
k = int(input())
for i in range(k):
	(x, y) = map(int, input().split(' '))
	if x > c:
		c = x
	if y < d:
		d = y
print(max(c - b, a - d, 0))


n = int(input())
N = 10000000000
(t1m, t1M, t2m, t2M) = (N, 0, N, 0)
for i in range(n):
	(a, b) = map(int, input().split())
	t1m = min(t1m, b)
	t1M = max(t1M, a)
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	t2m = min(t2m, b)
	t2M = max(t2M, a)
print(max(0, max(t2M - t1m, t1M - t2m)))


from sys import stdin, stdout
n = int(stdin.readline())
chessStart = []
chessEnd = []
for i in range(n):
	(l, r) = map(int, stdin.readline().rstrip().split())
	chessStart.append(l)
	chessEnd.append(r)
m = int(stdin.readline())
programStart = []
programEnd = []
for i in range(m):
	(l, r) = map(int, stdin.readline().rstrip().split())
	programStart.append(l)
	programEnd.append(r)
chessEarlyEnd = min(chessEnd)
chessLateStart = max(chessStart)
programEarlyEnd = min(programEnd)
programLateStart = max(programStart)
bestCase = max([chessLateStart - programEarlyEnd, programLateStart - chessEarlyEnd])
print(max([0, bestCase]))


n = int(input())
a = 10000000000.0
b = 0
for _ in range(n):
	(x, y) = map(int, input().split())
	if y < a:
		a = int(y)
	if x > b:
		b = x
m = int(input())
c = 10000000000.0
d = 0
for _ in range(m):
	(x, y) = map(int, input().split())
	if y < c:
		c = int(y)
	if x > d:
		d = x
print(max(0, b - c, d - a))


min_r1 = 1000000001
max_l1 = 0
max_l2 = 0
min_r2 = 1000000001
n = int(input())
for i in range(n):
	(l1, r1) = map(int, input().split())
	min_r1 = min(min_r1, r1)
	max_l1 = max(max_l1, l1)
m = int(input())
for i in range(m):
	(l2, r2) = map(int, input().split())
	min_r2 = min(min_r2, r2)
	max_l2 = max(max_l2, l2)
ans = 0
if min_r1 < max_l2:
	ans = max_l2 - min_r1
if min_r2 < max_l1:
	ans = max(ans, max_l1 - min_r2)
print(ans)


f = lambda : list(map(int, input().split()))
n = int(input())
(n_start, n_end) = (0, int(1000000000.0))
(m_start, m_end) = (0, int(1000000000.0))
for _ in range(n):
	(a, b) = f()
	n_start = max(n_start, a)
	n_end = min(n_end, b)
m = int(input())
for _ in range(m):
	(a, b) = f()
	m_start = max(m_start, a)
	m_end = min(m_end, b)
res = max(0, m_start - n_end, n_start - m_end)
print(res)


n = int(input())
a = 10000000000
a1 = -10000000000
for i in range(n):
	(x, y) = map(int, input().split())
	a = min(a, y)
	a1 = max(a1, x)
m = int(input())
b = -10000000000
b1 = 10000000000
for i in range(m):
	(x, y) = map(int, input().split())
	b = max(b, x)
	b1 = min(b1, y)
print(max(0, b - a, a1 - b1))


def ok(s, t, n, m):
	s = sorted(s, key=lambda x: x[1])
	t = sorted(t, key=lambda x: x[0])
	(x1, y1) = s[0]
	(x2, y2) = t[m - 1]
	ans = 0
	if y1 < x2:
		ans = x2 - y1
	return ans
n = int(input())
s = []
for i in range(n):
	(x, y) = map(int, input().split())
	s.append((x, y))
m = int(input())
t = []
for i in range(m):
	(x, y) = map(int, input().split())
	t.append((x, y))
ans = max(ok(s, t, n, m), ok(t, s, m, n))
print(ans)


inp = int(input())
minlchess = 0
minrchess = 10000000000
for i in range(inp):
	s = list(map(int, input().split()))
	leftchess = s[0]
	rightchess = s[1]
	if leftchess > minlchess:
		minlchess = leftchess
	if rightchess < minrchess:
		minrchess = rightchess
inp = int(input())
minlprog = 0
minrprog = 10000000000
for i in range(inp):
	s = list(map(int, input().split()))
	leftprog = s[0]
	rightprog = s[1]
	if leftprog > minlprog:
		minlprog = leftprog
	if rightprog < minrprog:
		minrprog = rightprog
dif1 = minlprog - minrchess
dif2 = minlchess - minrprog
if dif1 > dif2:
	if dif1 > 0:
		print(dif1)
	else:
		print('0')
elif dif2 > 0:
	print(dif2)
else:
	print('0')


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
n = I()
a = [0] * n
for i in range(n):
	a[i] = [0] * 2
	(a[i][0], a[i][1]) = R()
m = I()
b = [0] * m
for i in range(m):
	b[i] = [0] * 2
	(b[i][0], b[i][1]) = R()
a.sort(key=lambda x: x[1])
b.sort(key=lambda x: x[0])
ans = 0
ans = max(ans, max(b[m - 1][0] - a[0][1], 0))
a.sort(key=lambda x: x[0])
b.sort(key=lambda x: x[1])
ans = max(ans, max(a[n - 1][0] - b[0][1], 0))
print(ans)


(a, b, c, d) = ([], [], [], [])
n = int(input())
for _ in range(n):
	(l1, r1) = map(int, input().split())
	a.append(r1)
	c.append(l1)
m = int(input())
for _ in range(m):
	(l2, r2) = map(int, input().split())
	b.append(l2)
	d.append(r2)
if min(a) >= max(b) and min(d) >= max(c):
	print(0)
else:
	print(max(max(b) - min(a), max(c) - min(d)))


read = lambda : map(int, input().split())
n = int(input())
a = [tuple(read()) for i in range(n)]
m = int(input())
b = [tuple(read()) for i in range(m)]
fa = min((r for (l, r) in a))
fb = max((l for (l, r) in b))
ga = max((l for (l, r) in a))
gb = min((r for (l, r) in b))
ans = max(0, fb - fa, ga - gb)
print(ans)


n = int(input())
lst1 = []
for i in range(n):
	lst1.append([int(i) for i in input().split()])
m = int(input())
lst2 = []
for i in range(m):
	lst2.append([int(i) for i in input().split()])
lst1.sort(key=lambda x: x[1])
lst2.sort(key=lambda x: x[0])
num1 = lst2[-1][0] - lst1[0][1]
lst2.sort(key=lambda x: x[1])
lst1.sort(key=lambda x: x[0])
num2 = lst1[-1][0] - lst2[0][1]
num = max(num1, num2)
if num > 0:
	print(num)
else:
	print(0)


import sys
n = int(input())
clmax = colmax = -sys.maxsize
crmin = cormin = sys.maxsize
for _ in range(n):
	(l, r) = map(int, input().split())
	clmax = max(clmax, l)
	crmin = min(crmin, r)
m = int(input())
for _ in range(m):
	(l, r) = map(int, input().split())
	colmax = max(colmax, l)
	cormin = min(cormin, r)
result = max(colmax - crmin, clmax - cormin)
if result > 0:
	print(result)
else:
	print('0')


n = int(input())
min_r1 = 2 * 10 ** 9
max_l1 = 0
while n > 0:
	(l1, r1) = [int(x) for x in input().split()]
	if r1 < min_r1:
		min_r1 = r1
	if l1 > max_l1:
		max_l1 = l1
	n -= 1
m = int(input())
min_r2 = 2 * 10 ** 9
max_l2 = 0
while m > 0:
	(l2, r2) = [int(x) for x in input().split()]
	if r2 < min_r2:
		min_r2 = r2
	if l2 > max_l2:
		max_l2 = l2
	m -= 1
if max_l2 - min_r1 >= 0 and max_l1 - min_r2 >= 0:
	print(max(max_l2 - min_r1, max_l1 - min_r2))
elif max_l2 - min_r1 >= 0:
	print(max_l2 - min_r1)
elif max_l1 - min_r2 >= 0:
	print(max_l1 - min_r2)
else:
	print(0)


n1 = int(input())
endmin1 = 10 ** 9 + 1
endmin2 = 10 ** 9 + 1
(startmax1, startmax2) = (0, 0)
for i in range(n1):
	(a, b) = map(int, input().split())
	if b < endmin1:
		endmin1 = b
	if a > startmax1:
		startmax1 = a
n2 = int(input())
for i in range(n2):
	(c, d) = map(int, input().split())
	if c > startmax2:
		startmax2 = c
	if d < endmin2:
		endmin2 = d
if max(startmax2 - endmin1, startmax1 - endmin2) > 0:
	print(max(startmax2 - endmin1, startmax1 - endmin2))
else:
	print(0)


n = int(input())
minlr1 = 10 ** 9
minlr2 = 10 ** 9
maxlr1 = 1
maxlr2 = 1
for i in range(n):
	lr1 = input().split()
	if int(lr1[0]) > maxlr1:
		maxlr1 = int(lr1[0])
	if int(lr1[1]) < minlr1:
		minlr1 = int(lr1[1])
m = int(input())
for i in range(m):
	lr2 = input().split()
	if int(lr2[0]) > maxlr2:
		maxlr2 = int(lr2[0])
	if int(lr2[1]) < minlr2:
		minlr2 = int(lr2[1])
print(max(maxlr2 - minlr1, maxlr1 - minlr2, 0))


n = int(input())
chess = {'l_max': 1, 'r_min': 1000000000.0}
for _ in range(n):
	(l, r) = input().split()
	l = int(l)
	r = int(r)
	if chess['l_max'] < l:
		chess['l_max'] = l
	if chess['r_min'] > r:
		chess['r_min'] = r
n = int(input())
prog = {'l_max': 1, 'r_min': 1000000000.0}
for _ in range(n):
	(l, r) = input().split()
	l = int(l)
	r = int(r)
	if prog['l_max'] < l:
		prog['l_max'] = l
	if prog['r_min'] > r:
		prog['r_min'] = r
d1 = prog['l_max'] - chess['r_min']
d2 = chess['l_max'] - prog['r_min']
if d1 > d2:
	if d1 > 0:
		print(d1)
	else:
		print(0)
elif d2 > 0:
	print(d2)
else:
	print(0)


n = int(input())
a1 = []
armin = 1000000000000000.0
for i in range(0, n):
	(a, b) = map(int, input().split())
	armin = min(armin, b)
	a1.append((a, b))
m = int(input())
a2 = []
brmin = 1000000000000000.0
for i in range(0, m):
	(a, b) = map(int, input().split())
	brmin = min(brmin, b)
	a2.append((a, b))
ans = 0
for i in range(0, n):
	ans = max(ans, a1[i][0] - brmin)
for i in range(0, m):
	ans = max(ans, a2[i][0] - armin)
print(ans)


def dist_interval(a, b):
	(p0, q0) = a
	(p1, q1) = b
	if not (q0 <= p1 or q1 <= p0):
		return 0
	return min(abs(p1 - q0), abs(q1 - p0))

def main():
	n_chess_classes = int(input())
	chess_interval = [tuple(map(int, input().split())) for _ in range(n_chess_classes)]
	m_prog_classes = int(input())
	prog_interval = [tuple(map(int, input().split())) for _ in range(m_prog_classes)]
	ans = max(dist_interval(min(chess_interval, key=lambda x: x[1]), max(prog_interval)), dist_interval(min(prog_interval, key=lambda x: x[1]), max(chess_interval)))
	print(ans)
main()


n = int(input())
c = []
for i in range(n):
	c.append(list(map(int, input().split())))
m = int(input())
p = []
for i in range(m):
	p.append(list(map(int, input().split())))
c.sort()
p.sort()
ans = 0
for i in range(n):
	ans = max(ans, p[-1][0] - c[i][1])
for i in range(m):
	ans = max(ans, c[-1][0] - p[i][1])
print(ans)


n = int(input())
l3 = []
l1 = []
l2 = []
e = 0
f = 0
g = 0
l4 = []
l5 = []
for i in range(n):
	(a, b) = input().split()
	(a, b) = (int(a), int(b))
	l1.append(b)
	l2.append(a)
m = int(input())
for j in range(m):
	(c, d) = input().split()
	(c, d) = (int(c), int(d))
	l3.append(c)
	l4.append(d)
e = max(l3) - min(l1)
f = max(l2) - min(l4)
g = max(e, f)
if g > 0:
	print(g)
else:
	print(0)


n = int(input())
chess1 = []
chess2 = []
max1 = []
max2 = []
for i in range(0, n):
	[l, r] = map(int, input().split())
	max1.append(l)
	chess1.append(r)
m = int(input())
for i in range(0, m):
	(l, r) = map(int, input().split())
	max2.append(r)
	chess2.append(l)
max1.sort()
max2.sort()
chess1.sort()
chess2.sort()
s = max1[n - 1] - max2[0]
ss = chess2[m - 1] - chess1[0]
if s > ss and s > 0:
	print(s)
elif ss > s and ss > 0:
	print(ss)
else:
	print(0)


def func():
	n = int(input())
	mnr = 10 ** 9 + 1
	mxl = 0
	for i in range(n):
		(l, r) = [int(x) for x in input().split()]
		mnr = min(mnr, r)
		mxl = max(mxl, l)
	return (mxl, mnr)
(l1, r1) = func()
(l2, r2) = func()
print(max(l1 - r2, l2 - r1, 0))


import sys
mxl1 = mxl2 = -sys.maxsize
minr1 = minr2 = sys.maxsize
for i in range(int(input())):
	(m, n) = map(int, input().rstrip().split())
	mxl1 = max(mxl1, m)
	minr1 = min(minr1, n)
for i in range(int(input())):
	(p, q) = map(int, input().rstrip().split())
	mxl2 = max(mxl2, p)
	minr2 = min(minr2, q)
res = max(mxl2 - minr1, mxl1 - minr2)
print(max(res, 0))


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from itertools import accumulate

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def common(l1, l2):
	return set(l1).intersection(l2)

def solution():
	n = Int()
	mi1 = sys.maxsize
	ma1 = 0
	for i in range(n):
		(a, b) = Mint()
		mi1 = min(mi1, b)
		ma1 = max(ma1, a)
	m = Int()
	ma2 = 0
	mi2 = sys.maxsize
	for i in range(m):
		(a, b) = Mint()
		ma2 = max(ma2, a)
		mi2 = min(mi2, b)
	if ma1 < mi2 and mi1 > ma2:
		print(0)
	else:
		print(max(ma2 - mi1, ma1 - mi2))
solution()


n = int(input())
mincr = 10000000000.0
maxcl = 0
for i in range(0, n):
	s = input().split()
	period = [int(s[0]), int(s[1])]
	mincr = min(mincr, period[1])
	maxcl = max(maxcl, period[0])
m = int(input())
minpr = 10000000000.0
maxpl = 0
for i in range(0, m):
	s = input().split()
	period = [int(s[0]), int(s[1])]
	minpr = min(minpr, period[1])
	maxpl = max(maxpl, period[0])
ans = max(maxpl - mincr, maxcl - minpr)
ans = max(ans, 0)
print(ans)


n = int(input())
(m0, m11, m1, m2) = (10000000000.0, 0, 10000000000.0, 0)
for i in range(n):
	(l1, r1) = map(int, input().split())
	m0 = min(r1, m0)
	m11 = max(l1, m11)
m = int(input())
for i in range(m):
	(l1, r1) = map(int, input().split())
	m1 = min(r1, m1)
	m2 = max(l1, m2)
t = 0
r = max(m2 - m0, m11 - m1)
print(max(t, r))


p = []
q = []
r = []
s = []
n = int(input())
for _ in range(n):
	(x, y) = map(int, input().split())
	p.append(x)
	q.append(y)
m = int(input())
for _ in range(m):
	(a, b) = map(int, input().split())
	r.append(a)
	s.append(b)
mini1 = min(q)
maxi1 = max(r)
mini2 = min(s)
maxi2 = max(p)
diff = [maxi1 - mini1, maxi2 - mini2]
ans = max(diff)
if ans > 0:
	print(ans)
else:
	print(0)


(a, b, a2, b2) = ([], [], [], [])
n = int(input())
for i in range(n):
	t = input().split()
	a.append(int(t[0]))
	b.append(int(t[1]))
z = int(input())
for i in range(z):
	t = input().split()
	a2.append(int(t[0]))
	b2.append(int(t[1]))
perv = 0
vt = 0
if max(a2) > min(b):
	perv = max(a2) - min(b)
if max(a) > min(b2):
	vt = max(a) - min(b2)
if perv != 0 or vt != 0:
	print(max(perv, vt))
else:
	print(0)


n = int(input())
l1 = []
r1 = []
for i in range(n):
	(a, b) = [int(y) for y in input().split()]
	l1.append(a)
	r1.append(b)
m = int(input())
l2 = []
r2 = []
for i in range(m):
	(a, b) = [int(y) for y in input().split()]
	l2.append(a)
	r2.append(b)
ans = 0
if max(l2) - min(r1) > ans:
	ans = max(l2) - min(r1)
if max(l1) - min(r2) > ans:
	ans = max(l1) - min(r2)
print(ans)


n = int(input())
arr = [(0, 0) for _ in range(n)]
ml1 = ml2 = -10 ** 9
mr1 = mr2 = 10 ** 9
for i in range(n):
	(l, r) = map(int, input().split())
	ml1 = max(ml1, l)
	mr1 = min(mr1, r)
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	ml2 = max(ml2, l)
	mr2 = min(mr2, r)
ans = ml2 - mr1
ans1 = ml1 - mr2
print(max(ans, ans1, 0))


n = int(input())
mir = 99999999999999999999
mal = -1
for i in range(n):
	(l, r) = map(int, input().split())
	mir = min(mir, r)
	mal = max(l, mal)
ans = 0
for i in range(int(input())):
	(l, r) = map(int, input().split())
	ans = max(ans, l - mir, mal - r)
print(ans)


(mn, mx) = (1 << 31, 0)
(mn1, mx1) = (1 << 31, 0)

def li():
	return list(map(int, input().split()))
for x in range(int(input())):
	(l, r) = li()
	if r < mn:
		mn = r
	if mx1 < l:
		mx1 = l
for x in range(int(input())):
	(l, r) = li()
	if l > mx:
		mx = l
	if mn1 > r:
		mn1 = r
if mx > mn or mx1 > mn1:
	print(max(mx - mn, mx1 - mn1))
else:
	print(0)


n = int(input())
chess_start = 0
chess_end = 100000000000
prog_start = 0
prog_end = 100000000000
for i in range(n):
	(s, f) = map(int, input().split())
	if s > chess_start:
		chess_start = s
	if f < chess_end:
		chess_end = f
m = int(input())
for i in range(m):
	(s, f) = map(int, input().split())
	if s > prog_start:
		prog_start = s
	if f < prog_end:
		prog_end = f
chessfirst = prog_start - chess_end
progfirst = chess_start - prog_end
print(max(0, chessfirst, progfirst))


from sys import stdin
numPeriodsChess = int(stdin.readline().rstrip())
(maxChessStart, minChessEnd) = map(int, stdin.readline().rstrip().split())
for i in range(numPeriodsChess - 1):
	(a, b) = map(int, stdin.readline().rstrip().split())
	minChessEnd = min(b, minChessEnd)
	maxChessStart = max(a, maxChessStart)
numPeriodsProg = int(stdin.readline().rstrip())
(maxProgStart, minProgEnd) = map(int, stdin.readline().rstrip().split())
for i in range(numPeriodsProg - 1):
	(a, b) = map(int, stdin.readline().rstrip().split())
	minProgEnd = min(b, minProgEnd)
	maxProgStart = max(a, maxProgStart)
res = max(maxChessStart - minProgEnd, maxProgStart - minChessEnd)
if res < 0:
	print(0)
else:
	print(res)


max_start_i = max_start_j = 0
min_end_i = min_end_j = 10 ** 10
for _ in range(int(input())):
	(x, y) = list(map(int, input().split()))
	if x > max_start_i:
		max_start_i = x
	if y < min_end_i:
		min_end_i = y
for _ in range(int(input())):
	(x, y) = list(map(int, input().split()))
	if x > max_start_j:
		max_start_j = x
	if y < min_end_j:
		min_end_j = y
res = max(max_start_i - min_end_j, max_start_j - min_end_i)
print(res if res > 0 else 0)


import sys
import re
input = lambda : sys.stdin.readline()
import functools

@functools.lru_cache(maxsize=10000)
def Main():
	n = int(input())
	mnr = 123456789123
	mxl = -123456789123
	for _ in range(n):
		(l, r) = map(int, input().split())
		mnr = min(mnr, r)
		mxl = max(mxl, l)
	ans = 0
	m = int(input())
	for _ in range(m):
		(l, r) = map(int, input().split())
		ans = max(ans, l - mnr)
		ans = max(ans, mxl - r)
	print(ans)
Main()


(mnr1, mnr2, mxl1, mxl2) = (int(2000000000.0), int(2000000000.0), int(-2000000000.0), int(-2000000000.0))
n = int(input())
for _ in range(n):
	(l, r) = map(int, input().split())
	mnr1 = min(mnr1, r)
	mxl1 = max(mxl1, l)
m = int(input())
for _ in range(m):
	(l, r) = map(int, input().split())
	mnr2 = min(mnr2, r)
	mxl2 = max(mxl2, l)
print(max(0, mxl2 - mnr1, mxl1 - mnr2))


def intersect(tupla1, tupla2):
	if tupla1[1] >= tupla2[0]:
		if tupla1[1] <= tupla2[1] and tupla1[1] >= tupla2[0]:
			return True
		elif tupla1[0] <= tupla2[1] and tupla1[0] >= tupla2[0]:
			return True
	elif tupla2[1] <= tupla1[1] and tupla2[1] >= tupla1[0]:
		return True
	elif tupla2[0] <= tupla1[1] and tupla2[0] >= tupla1[0]:
		return True
	return False

def dif(tupla1, tupla2):
	inter = intersect(tupla1, tupla2)
	if inter:
		return 0
	maximo = 0
	if tupla1[1] >= tupla2[0]:
		maximo = tupla1[0] - tupla2[1]
	else:
		maximo = tupla2[0] - tupla1[1]
	return maximo
n = int(input())
tuplaNMayor = ()
tuplaNMenor = ()
infMayor = 0
supMenor = float('Inf')
for i in range(n):
	(l, r) = map(int, input().strip().split())
	if l > infMayor:
		infMayor = l
		tuplaNMayor = (l, r)
	if r < supMenor:
		supMenor = r
		tuplaNMenor = (l, r)
m = int(input())
tuplaMMayor = ()
tuplaMMenor = ()
infMayor = 0
supMenor = float('Inf')
for i in range(m):
	(l, r) = map(int, input().strip().split())
	if l > infMayor:
		infMayor = l
		tuplaMMayor = (l, r)
	if r < supMenor:
		supMenor = r
		tuplaMMenor = (l, r)
maximo = 0
aux = dif(tuplaMMayor, tuplaNMayor)
if aux > maximo:
	maximo = aux
aux = dif(tuplaMMayor, tuplaNMenor)
if aux > maximo:
	maximo = aux
aux = dif(tuplaMMenor, tuplaNMayor)
if aux > maximo:
	maximo = aux
aux = dif(tuplaMMenor, tuplaNMenor)
if aux > maximo:
	maximo = aux
print(maximo)


a = [[], []]
ch = int(input())
for i in range(ch):
	(r1, r2) = input().split()
	a[0].append(int(r1))
	a[1].append(int(r2))
b = [[], []]
pr = int(input())
for i in range(pr):
	(r1, r2) = input().split()
	b[0].append(int(r1))
	b[1].append(int(r2))
aa = (max(a[0]), min(a[1]))
bb = (max(b[0]), min(b[1]))
o = max(max(a[0]) - min(b[1]), max(b[0]) - min(a[1]))
if o < 0:
	o = 0
print(o)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
l1 = []
l2 = []
for i in range(n):
	(a, b) = M()
	l1.append(b)
	l2.append(a)
n = I()
x1 = []
x2 = []
for i in range(n):
	(a, b) = M()
	x1.append(a)
	x2.append(b)
print(max(max(x1) - min(l1), max(l2) - min(x2), 0))


n = int(input())
for i in range(n):
	(l1, r1) = input().strip().split(' ')
	(l1, r1) = (int(l1), int(r1))
	if i == 0:
		a1 = l1
		b1 = r1
	else:
		if l1 > a1:
			a1 = l1
		if r1 < b1:
			b1 = r1
m = int(input())
for i in range(m):
	(l1, r1) = input().strip().split(' ')
	(l1, r1) = (int(l1), int(r1))
	if i == 0:
		a2 = l1
		b2 = r1
	else:
		if l1 > a2:
			a2 = l1
		if r1 < b2:
			b2 = r1
ans1 = a2 - b1
ans2 = a1 - b2
if ans1 <= 0 and ans2 <= 0:
	print(0)
else:
	print(max(ans1, ans2))


def anton(n, m, a, b):
	mina = 1000000001
	for i in a:
		if i[1] < mina:
			mina = i[1]
	a.sort()
	maxa = a[-1][0]
	minb = 1000000001
	for i in b:
		if i[1] < minb:
			minb = i[1]
	b.sort()
	maxb = b[-1][0]
	v = maxb - mina
	w = maxa - minb
	if v >= w and v > 0:
		return v
	if w > v and w > 0:
		return w
	else:
		return 0
n = int(input().strip())
v = []
for i in range(n):
	x = []
	(a, b) = input().strip().split()
	x.append(int(a))
	x.append(int(b))
	v.append(x)
m = int(input().strip())
w = []
for i in range(m):
	x = []
	(a, b) = input().strip().split()
	x.append(int(a))
	x.append(int(b))
	w.append(x)
print(anton(n, m, v, w))


n = int(input())
(mini1, mini2, maxi1, maxi2) = (float('inf'), float('inf'), 0, 0)
for i in range(n):
	(a, b) = map(int, input().split())
	mini1 = min(mini1, b)
	maxi1 = max(maxi1, a)
for i in range(int(input())):
	(a, b) = map(int, input().split())
	mini2 = min(b, mini2)
	maxi2 = max(a, maxi2)
print(max(maxi2 - mini1, maxi1 - mini2, 0))


n = int(input())
(l, r) = map(int, input().split())
maximuml1 = (l, r)
minimumr1 = (l, r)
for i in range(n - 1):
	(l, r) = map(int, input().split())
	if l > maximuml1[0]:
		maximuml1 = (l, r)
	if r < minimumr1[1]:
		minimumr1 = (l, r)
m = int(input())
(l, r) = map(int, input().split())
maximuml2 = (l, r)
minimumr2 = (l, r)
for i in range(m - 1):
	(l, r) = map(int, input().split())
	if l > maximuml2[0]:
		maximuml2 = (l, r)
	if r < minimumr2[1]:
		minimumr2 = (l, r)
print(max(maximuml1[0] - minimumr2[1], maximuml2[0] - minimumr1[1], 0))


minn = 999999999999
maxn = 0
minm = 999999999999
maxm = 0
for n in range(int(input())):
	(l, r) = map(int, input().split())
	minn = min(minn, r)
	maxn = max(maxn, l)
for m in range(int(input())):
	(l, r) = map(int, input().split())
	minm = min(minm, r)
	maxm = max(maxm, l)
print(max([maxm - minn, maxn - minm, 0]))


n = int(input())
ms1 = 0
mt1 = 20000000000
ms2 = 0
mt2 = 20000000000
for _ in range(n):
	(s, t) = [int(x) for x in input().split()]
	ms1 = max(ms1, s)
	mt1 = min(mt1, t)
m = int(input())
for _ in range(m):
	(s, t) = [int(x) for x in input().split()]
	ms2 = max(ms2, s)
	mt2 = min(mt2, t)
dif = max(ms1 - mt2, ms2 - mt1)
print(max(0, dif))


n = int(input())
r = lambda : map(int, input().split())
chess = [list(r()) for _ in range(n)]
n = int(input())
code = [list(r()) for _ in range(n)]
(chess_max_start, chess_min_end) = (max((x[0] for x in chess)), min((x[1] for x in chess)))
(code_max_start, code_min_end) = (max((x[0] for x in code)), min((x[1] for x in code)))
d = max(chess_max_start - code_min_end, code_max_start - chess_min_end)
print(max(0, d))


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from itertools import combinations, permutations
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
arr = [rr() for i in range(n)]
m = ii()
brr = [rr() for i in range(m)]
a = [i for (i, j) in arr]
b = [j for (i, j) in arr]
c = [i for (i, j) in brr]
d = [j for (i, j) in brr]
a = max(a)
b = min(b)
c = max(c)
d = min(d)
x = max(0, c - b)
y = max(0, a - d)
print(max(x, y))


n = int(input())
array_one = [0] * n
array_one_upd = [0] * n
for i in range(n):
	(a, b) = map(int, input().split())
	array_one[i] = [a, b]
	array_one_upd[i] = [b, a]
m = int(input())
array_two = [0] * m
array_two_upd = [0] * m
for i in range(m):
	(a, b) = map(int, input().split())
	array_two[i] = [a, b]
	array_two_upd[i] = [b, a]
array_one.sort()
array_one_upd.sort()
array_two.sort()
array_two_upd.sort()
probable_answer = max(array_one[-1][0] - array_two_upd[0][0], array_two[-1][0] - array_one_upd[0][0])
print(max(probable_answer, 0))


n = int(input())
(max_chess, max_cp) = (0, 0)
(min_chess, min_cp) = (10 ** 10, 10 ** 10)
for i in range(n):
	x = list(map(int, input().split()))
	if x[0] > max_chess:
		max_chess = x[0]
	if x[1] < min_chess:
		min_chess = x[1]
m = int(input())
for j in range(m):
	x = list(map(int, input().split()))
	if x[0] > max_cp:
		max_cp = x[0]
	if x[1] < min_cp:
		min_cp = x[1]
if max_cp - min_chess >= 0 and max_chess - min_cp >= 0:
	print(max(max_cp - min_chess, max_chess - min_cp))
elif max_cp - min_chess >= 0 and max_chess - min_cp < 0:
	print(max_cp - min_chess)
elif max_cp - min_chess < 0 and max_chess - min_cp >= 0:
	print(max_chess - min_cp)
else:
	print(0)


n = int(input())
arr = [tuple(map(int, input().split())) for _ in range(n)]
m = int(input())
brr = [tuple(map(int, input().split())) for _ in range(m)]
mini = float('inf')
maxi = float('-inf')
for i in range(n):
	mini = min(arr[i][1], mini)
for i in range(m):
	maxi = max(brr[i][0], maxi)
tot = maxi - mini
mini = float('inf')
maxi = float('-inf')
for i in range(m):
	mini = min(brr[i][1], mini)
for i in range(n):
	maxi = max(arr[i][0], maxi)
tot = max(tot, maxi - mini)
if tot < 0:
	print(0)
else:
	print(tot)


n = int(input())
(nleftmax, nrightmin, mleftmax, mrightmin) = (0, 10 ** 10, 0, 10 ** 10)
for i in range(n):
	(a, b) = map(int, input().split())
	if a > nleftmax:
		nleftmax = a
	if b < nrightmin:
		nrightmin = b
m = int(input())
for i in range(m):
	(a, b) = map(int, input().split())
	if a > mleftmax:
		mleftmax = a
	if b < mrightmin:
		mrightmin = b
c = max(mleftmax - nrightmin, nleftmax - mrightmin)
if c > 0:
	print(c)
else:
	print(0)


n = int(input())
mn = 10 ** 10
mn2 = 10 ** 10
mx = 0
mx2 = 0
for i in range(n):
	(x, y) = map(int, input().split())
	mn = min(y, mn)
	mx2 = max(x, mx2)
m = int(input())
for i in range(m):
	(x, y) = map(int, input().split())
	mx = max(x, mx)
	mn2 = min(y, mn2)
print(max(0, max(mx - mn, mx2 - mn2)))


n = int(input())
l1 = [0] * n
r1 = [0] * n
for i in range(n):
	(l1[i], r1[i]) = list(map(int, input().split()))
maxl1 = max(l1)
minr1 = min(r1)
n = int(input())
l1 = [0] * n
r1 = [0] * n
for i in range(n):
	(l1[i], r1[i]) = list(map(int, input().split()))
maxl2 = max(l1)
minr2 = min(r1)
print(max(0, maxl1 - minr2, maxl2 - minr1))


n = int(input())
x1 = []
x10 = []
for a in range(n):
	(t1, t2) = map(int, input().split())
	x1.append(t2)
	x10.append(t1)
m = int(input())
x2 = []
x20 = []
for b in range(m):
	(t3, t4) = map(int, input().split())
	x2.append(t3)
	x20.append(t4)
x1 = sorted(x1)
x2 = sorted(x2)
x10 = sorted(x10)
x20 = sorted(x20)
ans1 = x2[m - 1] - x1[0]
ans2 = x10[n - 1] - x20[0]
if ans1 > 0 or ans2 > 0:
	print(max(ans1, ans2))
else:
	print(0)


n = int(input())
lri1 = [list(map(int, input().split())) for i in range(n)]
m = int(input())
lri2 = [list(map(int, input().split())) for i in range(m)]
min_r1 = lri1[0][1]
min_r2 = lri2[0][1]
max_l2 = lri2[0][0]
max_l1 = lri1[0][0]
for i in range(n):
	min_r1 = min(min_r1, lri1[i][1])
	max_l1 = max(max_l1, lri1[i][0])
for i in range(m):
	min_r2 = min(min_r2, lri2[i][1])
	max_l2 = max(max_l2, lri2[i][0])
print(max(0, max(max_l2 - min_r1, max_l1 - min_r2)))


n = int(input())
(r1, r2) = ([], [])
for i in range(n):
	(start, finish) = map(int, input().split())
	r1.append(start)
	r2.append(finish)
m = int(input())
(r3, r4) = ([], [])
for i in range(m):
	(start2, finish2) = map(int, input().split())
	r3.append(start2)
	r4.append(finish2)
maxstart1 = max(r1)
minfinish1 = min(r2)
maxstart2 = max(r3)
minfinish2 = min(r4)
ans = max(0, maxstart1 - minfinish2, maxstart2 - minfinish1)
print(ans)


from sys import stdin
polyDict = {'Icosahedron': 20, 'Cube': 6, 'Octahedron': 8, 'Dodecahedron': 12, 'Tetrahedron': 4}
array = []
for line in stdin:
	array.append(line.rstrip())
n = int(array[0])
chessArr = []
progArr = []
for i in range(1, n + 1):
	chessArr.append([int(x) for x in array[i].rstrip().split()])
m = int(array[n + 1])
for i in range(n + 2, len(array)):
	progArr.append([int(x) for x in array[i].rstrip().split()])
minCEnd = min([chessArr[i][1] for i in range(len(chessArr))])
maxCStart = max([chessArr[i][0] for i in range(len(chessArr))])
maxPStart = max([progArr[i][0] for i in range(len(progArr))])
minPEnd = min([progArr[i][1] for i in range(len(progArr))])
diff1 = maxPStart - minCEnd
diff2 = maxCStart - minPEnd
ret = max(diff1, diff2)
if ret > 0:
	print(str(ret))
else:
	print('0')


n = int(input())
chess = [list(map(int, input().split(' '))) for i in range(n)]
m = int(input())
programming = [list(map(int, input().split(' '))) for i in range(m)]
result = 0
chess.sort(key=lambda x: x[1])
programming.sort(key=lambda x: x[0])
result = max(result, programming[m - 1][0] - chess[0][1])
chess.sort(key=lambda x: x[0])
programming.sort(key=lambda x: x[1])
result = max(result, chess[n - 1][0] - programming[0][1])
print(result)


n = int(input())
(al, ar) = map(int, input().split())
for _ in range(n - 1):
	(l, r) = map(int, input().split())
	al = max(al, l)
	ar = min(ar, r)
m = int(input())
(bl, br) = map(int, input().split())
for _ in range(m - 1):
	(l, r) = map(int, input().split())
	bl = max(bl, l)
	br = min(br, r)
ret = max(0, al - br, bl - ar)
print(ret)


n = int(input())
ch = []
for i in range(n):
	ch.append(list(map(int, input().split())))
p = []
m = int(input())
for i in range(m):
	p.append(list(map(int, input().split())))
sch = 10000000000000
bp = 0
for i in ch:
	if i[1] < sch:
		sch = i[1]
for i in p:
	if i[0] > bp:
		bp = i[0]
f = bp - sch
if f < 0:
	f = 0
(ch, p) = (p, ch)
sch = 10000000000000
bp = 0
for i in ch:
	if i[1] < sch:
		sch = i[1]
for i in p:
	if i[0] > bp:
		bp = i[0]
w = bp - sch
if w > f:
	f = w
print(f)


N = int(input())
L1 = []
R1 = []
for i in range(N):
	(l, r) = map(int, input().split())
	L1.append(l)
	R1.append(r)
M = int(input())
L2 = []
R2 = []
for i in range(M):
	(l, r) = map(int, input().split())
	L2.append(l)
	R2.append(r)
ans1 = max(max(L1) - min(R2), 0)
ans2 = max(max(L2) - min(R1), 0)
print(max(ans1, ans2))


n = int(input())
p = []
l = []
g = []
b = []
for x in range(n):
	(m, k) = list(map(int, input().split()))
	p.append(k)
	g.append(m)
ta = int(input())
for x in range(ta):
	(m, k) = list(map(int, input().split()))
	l.append(m)
	b.append(k)
tom = min(p)
lam = max(l)
fam = min(b)
opl = max(g)
if tom >= lam and fam >= opl:
	print('0')
else:
	print(max(lam - tom, opl - fam))


n = int(input().strip())
chess = []
for i in range(n):
	chess.append(tuple(map(int, input().strip().split())))
m = int(input().strip())
prog = []
for i in range(m):
	prog.append(tuple(map(int, input().strip().split())))
chess.sort(key=lambda x: x[1])
prog.sort(key=lambda x: x[0])
d1 = prog[-1][0] - chess[0][1]
prog.sort(key=lambda x: x[1])
chess.sort(key=lambda x: x[0])
d2 = chess[-1][0] - prog[0][1]
a = max(d1, d2)
a = a if a > 0 else 0
print(a)


def read(i):
	(mln, mrn) = (-1, 10 ** 19)
	for _ in range(i):
		(l, r) = map(int, input().split())
		if l > mln:
			mln = l
		if r < mrn:
			mrn = r
	return (mln, mrn)
n = int(input())
(ln, rn) = read(n)
m = int(input())
(lm, rm) = read(m)
diff = lambda r, l: 0 if r >= l else l - r
ans = max(diff(rm, ln), diff(rn, lm))
print(ans)


n = int(input())
mx = 0
mn = 10 ** 10
for i in range(n):
	(l, r) = list(map(int, input().split(' ')))
	mx = max(mx, l)
	mn = min(mn, r)
m = int(input())
ans = 0
for i in range(m):
	(l, r) = list(map(int, input().split(' ')))
	ans = max([ans, mx - r, l - mn])
print(ans)


x = 0
l = []
(max1, max2, min1, min2) = (0, 0, 10 ** 9 + 1, 10 ** 9 + 1)
n = int(input())
for i in range(n):
	x = list(map(int, input().split()))
	if max1 < x[0]:
		max1 = x[0]
	if min1 > x[1]:
		min1 = x[1]
l = []
n = int(input())
for i in range(n):
	x = list(map(int, input().split()))
	if max2 < x[0]:
		max2 = x[0]
	if min2 > x[1]:
		min2 = x[1]
x = max(max2 - min1, max1 - min2)
if x < 0:
	print('0')
else:
	print(x)


n = int(input())
l_1 = [None] * n
r_1 = [None] * n
for i in range(n):
	(l_1[i], r_1[i]) = map(int, input().split())
m = int(input())
l_2 = [None] * m
r_2 = [None] * m
for i in range(m):
	(l_2[i], r_2[i]) = map(int, input().split())
maximum = max(max(l_2) - min(r_1), max(l_1) - min(r_2))
print(maximum if maximum > 0 else 0)


n = int(input())
l1 = 1000000005
z2 = 1000000005
l2 = 0
z1 = 0
for i in range(0, n):
	(x, y) = input().split(' ')
	(x, y) = (int(x), int(y))
	l1 = min(y, l1)
	z1 = max(z1, x)
m = int(input())
for i in range(0, m):
	(x, y) = input().split(' ')
	(x, y) = (int(x), int(y))
	l2 = max(x, l2)
	z2 = min(z2, y)
o = max(z1 - z2, l2 - l1)
if o < 0:
	print('0')
else:
	print(o)


import itertools

def free_time_between(chess_lesson, programming_lesson):
	(chess_left, chess_right) = chess_lesson
	(programming_left, programming_right) = programming_lesson
	if programming_left <= chess_left <= programming_right:
		return 0
	elif chess_left <= programming_left <= chess_right:
		return 0
	else:
		ans = max(programming_left - chess_right, chess_left - programming_right)
		return ans
n = int(input())
programming = []
for i in range(n):
	time = [int(x) for x in input().split()]
	programming.append(time)
m = int(input())
chess = []
for i in range(m):
	time = [int(x) for x in input().split()]
	chess.append(time)
min_p_right = min(programming, key=lambda x: x[1])
max_p_left = max(programming, key=lambda x: x[0])
max_c_left = max(chess, key=lambda x: x[0])
min_c_right = min(chess, key=lambda x: x[1])
ans = max(free_time_between(min_p_right, max_c_left), free_time_between(min_c_right, max_p_left))
print(ans)


n = int(input())
chess = []
for i in range(n):
	chess.append(list(map(int, input().split())))
m = int(input())
prog = []
for i in range(m):
	prog.append(list(map(int, input().split())))
chess.sort(key=lambda x: x[1])
prog.sort()
poss1 = max(prog[-1][0] - chess[0][1], 0)
chess.sort()
prog.sort(key=lambda x: x[1])
poss2 = max(chess[-1][0] - prog[0][1], 0)
print(max(poss1, poss2))


from operator import itemgetter

def distance(t1, t2):
	if t2[0] >= t1[0] and t2[0] <= t1[1]:
		return 0
	if t2[1] >= t1[0] and t2[1] <= t1[1]:
		return 0
	if t1[0] > t2[1]:
		return t1[0] - t2[1]
	return t2[0] - t1[1]
l1 = []
l2 = []
n = int(input())
for i in range(n):
	t = tuple(map(int, input().split()))
	l1.append(t)
m = int(input())
for i in range(m):
	t = tuple(map(int, input().split()))
	l2.append(t)
sortedL1 = sorted(l1, key=itemgetter(1))
sortedL2 = sorted(l2, key=itemgetter(0))
ans = distance(sortedL1[0], sortedL2[m - 1])
sortedL1 = sorted(l1, key=itemgetter(0))
sortedL2 = sorted(l2, key=itemgetter(1))
ans = max(ans, distance(sortedL2[0], sortedL1[n - 1]))
print(ans)


n = int(input())
(max1, min1) = (0, 10000000000.0)
for i in range(n):
	l = [int(j) for j in input().split()]
	if l[1] < min1:
		min1 = l[1]
	if l[0] > max1:
		max1 = l[0]
m = int(input())
(max2, min2) = (0, 10000000000.0)
for i in range(m):
	l = [int(j) for j in input().split()]
	if l[1] < min2:
		min2 = l[1]
	if l[0] > max2:
		max2 = l[0]
(r1, r2) = (max1 - min2, max2 - min1)
if r1 > 0 or r2 > 0:
	print(max((r1, r2)))
else:
	print(0)


n = int(input())
maxln = 0
minrn = 10 ** 9 + 1
for i in range(n):
	(l, r) = map(int, input().split())
	maxln = max(l, maxln)
	minrn = min(r, minrn)
m = int(input())
ans = -1
for i in range(m):
	(l, r) = map(int, input().split())
	if l > minrn:
		ans = max(ans, l - minrn)
	if r < maxln:
		ans = max(ans, maxln - r)
ans = max(0, ans)
print(ans)


n = int(input())
is1 = []
is2 = []
js1 = []
js2 = []
for i in range(n):
	t = list(map(int, input().split()))
	is1.append(t[0])
	js1.append(t[1])
m = int(input())
for i in range(m):
	t = list(map(int, input().split()))
	is2.append(t[0])
	js2.append(t[1])
max1 = max(is1) - min(js2)
max2 = max(is2) - min(js1)
m = max(max1, max2)
if m < 0:
	print(0)
else:
	print(m)


ches = []
prog = []
for _ in range(int(input())):
	ches.append([int(el) for el in input().split()])
for _ in range(int(input())):
	prog.append([int(el) for el in input().split()])
ches.sort(key=lambda x: x[1])
prog.sort(key=lambda x: x[0])
one = prog[-1][0] - ches[0][1]
ches.sort(key=lambda x: x[0])
prog.sort(key=lambda x: x[1])
two = ches[-1][0] - prog[0][1]
prin = max(one, two)
if prin < 0:
	prin = 0
print(prin)


import math

def find_bounds(n):
	max_l = 0
	min_r = math.inf
	for i in range(n):
		(l, r) = map(int, input().split())
		if l > max_l:
			max_l = l
		if r < min_r:
			min_r = r
	return [max_l, min_r]
n = int(input())
(max_l1, min_r1) = find_bounds(n)
m = int(input())
(max_l2, min_r2) = find_bounds(m)
print('{}\n'.format(max(max_l2 - min_r1, max_l1 - min_r2, 0)))


from operator import itemgetter
n = int(input())
shakh = sorted([tuple(map(int, input().split())) for _ in range(n)], key=itemgetter(1))
n = int(input())
prog = sorted([tuple(map(int, input().split())) for _ in range(n)], reverse=True)
maxRest1 = 0 if shakh[0][1] > prog[0][0] else prog[0][0] - shakh[0][1]
shakh.sort(key=itemgetter(0), reverse=True)
prog.sort(key=itemgetter(1), reverse=False)
maxRest2 = 0 if prog[0][1] > shakh[0][0] else shakh[0][0] - prog[0][1]
print(max(maxRest1, maxRest2))


chessmin = 10000000000
chessmax = -1
progmin = 10000000000
progmax = -1
n = int(input())
for i in range(n):
	temp = input().split()
	if int(temp[1]) < chessmin:
		chessmin = int(temp[1])
	if int(temp[0]) > chessmax:
		chessmax = int(temp[0])
m = int(input())
for i in range(m):
	temp = input().split()
	if int(temp[1]) < progmin:
		progmin = int(temp[1])
	if int(temp[0]) > progmax:
		progmax = int(temp[0])
res = max(progmax - chessmin, chessmax - progmin)
if res < 0:
	res = 0
print(res)


(cl, cr, pl, pr) = ([], [], [], [])
for i in range(int(input())):
	(l, r) = map(int, input().split())
	cl.append(l)
	cr.append(r)
for i in range(int(input())):
	(l, r) = map(int, input().split())
	pl.append(l)
	pr.append(r)
print(max(0, max(pl) - min(cr), max(cl) - min(pr)))


n = int(input())
minN = 1000000000
maxN = 0
minM = 1000000000
maxM = 0
for i in range(n):
	(l, r) = [int(x) for x in input().split()]
	minN = min(minN, r)
	maxN = max(maxN, l)
m = int(input())
for i in range(m):
	(l, r) = [int(x) for x in input().split()]
	minM = min(minM, r)
	maxM = max(maxM, l)
res = max(maxM - minN, maxN - minM)
if res <= 0:
	print(0)
else:
	print(res)


n = int(input())
begins1 = []
ends1 = []
begins2 = []
ends2 = []
for i in range(n):
	(begin, end) = [int(x) for x in input().split()]
	begins1.append(begin)
	ends1.append(end)
m = int(input())
for i in range(m):
	(begin, end) = [int(x) for x in input().split()]
	begins2.append(begin)
	ends2.append(end)
begins1.sort()
ends1.sort()
begins2.sort()
ends2.sort()
print(max(0, begins2[m - 1] - ends1[0], begins1[n - 1] - ends2[0]))


mat = [0, 0]
sat = [0, 0]
for i in range(int(input())):
	(x, y) = map(int, input().split())
	if i == 0:
		mat[1] = y
	mat[0] = max(x, mat[0])
	mat[1] = min(y, mat[1])
for j in range(int(input())):
	(x, y) = map(int, input().split())
	if j == 0:
		sat[1] = y
	sat[0] = max(x, sat[0])
	sat[1] = min(y, sat[1])
print(max(mat[0] - sat[1], sat[0] - mat[1], 0))


n = int(input())
a = 10 ** 9
c = 1
for i in range(n):
	s = input().split(' ')
	a = min(a, int(s[1]))
	c = max(c, int(s[0]))
m = int(input())
b = 1
d = 10 ** 9
for i in range(m):
	s = input().split(' ')
	b = max(b, int(s[0]))
	d = min(d, int(s[1]))
ans = max(b - a, c - d)
if ans < 0:
	print(0)
else:
	print(ans)


a = int(input())
x = []
y = []
for i in range(a):
	add1 = input()
	add1 = list(map(int, add1.split()))
	x.append(add1)
b = int(input())
s = 0
for j in range(b):
	add2 = input()
	add2 = list(map(int, add2.split()))
	y.append(add2)
x.sort(key=lambda x: x[1])
y.sort()
diff1 = y[b - 1][0] - x[0][1]
x.sort()
y.sort(key=lambda y: y[1])
diff2 = x[a - 1][0] - y[0][1]
if diff1 > 0 or diff2 > 0:
	if diff2 > diff1:
		print(diff2)
	elif diff2 < diff1:
		print(diff1)
	else:
		print(0)
else:
	print(0)


n = int(input())
(A, B) = ([], [])
max = 0
minEA = 1000000000
minEB = 1000000000
maxSA = 0
maxSB = 0
for i in range(n):
	line = input().split()
	s = int(line[0])
	e = int(line[1])
	if e < minEA:
		minEA = e
	if s > maxSA:
		maxSA = s
m = int(input())
for i in range(m):
	line = input().split()
	s = int(line[0])
	e = int(line[1])
	if e < minEB:
		minEB = e
	if s > maxSB:
		maxSB = s
if maxSB - minEA > 0:
	max = maxSB - minEA
if maxSA - minEB > max:
	max = maxSA - minEB
print(max)


n = int(input())
arr1 = []
arr2 = []
for i in range(0, n):
	(x, y) = map(int, input().split())
	p = [x, y]
	arr1.append(p)
m = int(input())
for i in range(0, m):
	(x, y) = map(int, input().split())
	p = [x, y]
	arr2.append(p)
min1 = 10000000000
min2 = 10000000000
max1 = 0
max2 = 0
s1 = 0
s2 = 0
for i in range(0, n):
	if min1 > arr1[i][1]:
		min1 = arr1[i][1]
	if max1 < arr1[i][0]:
		max1 = arr1[i][0]
for i in range(0, m):
	if min2 > arr2[i][1]:
		min2 = arr2[i][1]
	if max2 < arr2[i][0]:
		max2 = arr2[i][0]
if min1 < max2:
	s1 = max2 - min1
if min2 < max1:
	s2 = max1 - min2
if s1 == 0 and s2 == 0:
	print(0)
	exit()
if s1 > s2:
	print(s1)
else:
	print(s2)


import sys

def read_bounds():
	left = right = None
	for _ in range(int(sys.stdin.readline())):
		(l, r) = map(int, sys.stdin.readline().split())
		left = min(r, left or r)
		right = max(l, right or l)
	return (left, right)
(chess_left, chess_right) = read_bounds()
(prog_left, prog_right) = read_bounds()
print(max(max(0, prog_right - chess_left), max(0, chess_right - prog_left)))


n = int(input())
mini1 = 1000000001
maxi1 = 0
for i in range(n):
	(a, b) = map(int, input().split())
	mini1 = min(mini1, b)
	maxi1 = max(maxi1, a)
m = int(input())
maxi2 = 0
mini2 = 1000000001
for i in range(m):
	(a, b) = map(int, input().split())
	maxi2 = max(maxi2, a)
	mini2 = min(mini2, b)
ans1 = 0
ans2 = 0
if maxi2 > mini1:
	ans1 = maxi2 - mini1
if mini2 < maxi1:
	ans2 = maxi1 - mini2
print(max(ans1, ans2))


def f():
	(a, b) = (1000000001, -1)
	for i in range(int(input())):
		s = input().split()
		a = min(a, int(s[1]))
		b = max(b, int(s[0]))
	return (a, b)
(a, b) = f()
(a1, b1) = f()
print(max(0, b1 - a, b - a1))


n = int(input())
a = sorted([[*map(int, input().split())] for _ in [0] * n])
m = int(input())
b = sorted([[*map(int, input().split())] for _ in [0] * m])
c = sorted(a, key=lambda x: x[1])
d = sorted(b, key=lambda x: x[1])
print(max(max(0, a[n - 1][0] - d[0][1]), max(0, b[m - 1][0] - c[0][1])))


n = int(input())
INF = 10 ** 10
st_s = -INF
st_p = -INF
fn_s = INF
fn_p = INF
for i in range(n):
	(l, r) = map(int, input().split())
	st_s = max(st_s, l)
	fn_s = min(fn_s, r)
m = int(input())
for i in range(m):
	(l, r) = map(int, input().split())
	st_p = max(st_p, l)
	fn_p = min(fn_p, r)
ans1 = max(0, st_s - fn_p)
ans2 = max(0, st_p - fn_s)
print(max(ans1, ans2))


n = int(input())
a = []
b = []
c = []
d = []
for i in range(n):
	(x, y) = map(int, input().split(' '))
	a.append(x)
	b.append(y)
m = int(input())
for i in range(m):
	(x, y) = map(int, input().split(' '))
	c.append(x)
	d.append(y)
ans1 = max(c) - min(b)
ans2 = max(a) - min(d)
print(max(ans1, ans2, 0))