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