#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> mp;
  for (int i = 0; i < 2; i++) {
    long long n;
    cin >> n;
    while (n--) {
      int a, b;
      cin >> a >> b;
      mp[a] = max(mp[a], b);
    }
  }
  long long sum = 0;
  map<int, int>::iterator ip;
  for (ip = mp.begin(); ip != mp.end(); ip++) {
    sum += ip->second;
  }
  cout << sum << endl;
  return 0;
}
