#include <bits/stdc++.h>
using namespace std;
int mn[4], mx[4], INF = 1000000010;
int main() {
  for (int i = 0; i < 2; i++) {
    int n, l, r;
    mn[i] = INF;
    mx[i] = -INF;
    cin >> n;
    for (int j = 0; j < n; j++) {
      cin >> l >> r;
      mn[i] = min(mn[i], r);
      mx[i] = max(mx[i], l);
    }
  }
  cout << max(0, max(mx[0] - mn[1], mx[1] - mn[0])) << endl;
  return 0;
}
