#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int maxn = 1e9, minn = -1e9;
long long modpow(long long base, long long exp, int modulus) {
  base %= modulus;
  long long result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
int main() {
  int n;
  cin >> n;
  int r = maxn, r2 = minn;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    r = min(r, b);
    r2 = max(r2, a);
  }
  int m;
  cin >> m;
  int l = minn, l2 = maxn;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    l = max(l, a);
    l2 = min(l2, b);
  }
  if (l <= r || r2 <= l2) {
    if (r2 <= l2 && l >= r)
      cout << l - r;
    else if (l <= r && r2 >= l2)
      cout << r2 - l2;
    else
      cout << 0;
  } else
    cout << max(r2 - l2, l - r);
  return 0;
}
