#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  int n;
  cin >> n;
  pair<int, int> chess = {0, INF};
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    chess.first = max(a, chess.first);
    chess.second = min(b, chess.second);
  }
  int m;
  cin >> m;
  pair<int, int> prog = {0, INF};
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    prog.first = max(a, prog.first);
    prog.second = min(b, prog.second);
  }
  cout << max(max(0, chess.first - prog.second),
              max(0, prog.first - chess.second));
}
