#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, l1 = INT_MIN, l2 = INT_MIN, r1 = INT_MAX, r2 = INT_MAX, l,
                      r;
  cin >> n;
  while (n--) {
    cin >> l >> r;
    l1 = max(l1, l);
    r1 = min(r1, r);
  }
  cin >> m;
  while (m--) {
    cin >> l >> r;
    l2 = max(l2, l);
    r2 = min(r2, r);
  }
  cout << max((long long int)0, max(l1 - r2, l2 - r1));
  return 0;
}
