#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  map<int, int> My;
  int n;
  cin >> n;
  while (n--) {
    int x, y;
    cin >> x >> y;
    My[x] = max(My[x], y);
  }
  cin >> n;
  while (n--) {
    int x, y;
    cin >> x >> y;
    My[x] = max(My[x], y);
  }
  map<int, int>::iterator it;
  long long ans = 0;
  for (it = My.begin(); it != My.end(); it++) {
    ans += (it->second);
  }
  cout << ans << endl;
}
