#include <bits/stdc++.h>
using namespace std;
long long n, m, l, r, ml1, ml2, mr1, mr2;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  mr1 = mr2 = 1e9;
  for (int i = 0; i < n; ++i)
    cin >> l >> r, ml1 = max(ml1, l), mr1 = min(mr1, r);
  cin >> m;
  for (int i = 0; i < m; ++i)
    cin >> l >> r, ml2 = max(ml2, l), mr2 = min(mr2, r);
  cout << max(0LL, max(ml1 - mr2, ml2 - mr1)) << endl;
  return 0;
}
