#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 5;
void solve() {
  long long n;
  cin >> n;
  long long a[2][2];
  a[0][0] = a[1][0] = -INF;
  a[0][1] = a[1][1] = INF;
  for (long long i = 0; i < n; i++) {
    long long first, second;
    cin >> first >> second;
    a[0][0] = max(a[0][0], first);
    a[0][1] = min(a[0][1], second);
  }
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long first, second;
    cin >> first >> second;
    a[1][0] = max(a[1][0], first);
    a[1][1] = min(a[1][1], second);
  }
  long long ans = -INF;
  if (a[0][1] <= a[1][0]) ans = a[1][0] - a[0][1];
  if (a[1][1] <= a[0][0]) ans = max(ans, a[0][0] - a[1][1]);
  if (ans == -INF)
    cout << 0 << endl;
  else
    cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}
