#include <bits/stdc++.h>
using namespace std;
struct time {
  int s;
  int e;
};
int main() {
  int n;
  cin >> n;
  int s, e;
  int minc = INT_MAX, maxc = -1;
  for (int i = 0; i < n; i++) {
    cin >> s >> e;
    if (minc > e) {
      minc = e;
    }
    if (maxc < s) {
      maxc = s;
    }
  }
  int m;
  cin >> m;
  int maxp = -1, minp = INT_MAX;
  for (int i = 0; i < m; i++) {
    cin >> s >> e;
    if (minp > e) {
      minp = e;
    }
    if (maxp < s) {
      maxp = s;
    }
  }
  int p = maxp - minc;
  int q = maxc - minp;
  if (p < 0 && q < 0) {
    cout << 0;
  } else {
    cout << max(p, q);
  }
}
