#include <bits/stdc++.h>
int mx, mn, n, k, l, mx2, mn2;
int main() {
  scanf("%d", &n);
  n--;
  scanf("%d%d", &mx, &mn);
  while (n--) {
    scanf("%d%d", &k, &l);
    if (l < mn) mn = l;
    if (k > mx) mx = k;
  }
  scanf("%d", &n);
  n--;
  scanf("%d%d", &mx2, &mn2);
  while (n--) {
    scanf("%d%d", &k, &l);
    if (l < mn2) mn2 = l;
    if (k > mx2) mx2 = k;
  }
  n = mx - mn2;
  if (n < mx2 - mn) n = mx2 - mn;
  if (n < 0) n = 0;
  printf("%d\n", n);
  return 0;
}
