#include <bits/stdc++.h>
using namespace std;
long long powermod(long long _a, long long _b, long long _m) {
  long long _r = 1;
  while (_b) {
    if (_b % 2 == 1) _r = (_r * _a) % _m;
    _b /= 2;
    _a = (_a * _a) % _m;
  }
  return _r;
}
long long string_to_number(string s) {
  long long x = 0;
  stringstream convert(s);
  convert >> x;
  return x;
}
long long add(long long a, long long b) {
  long long x = (a + b) % 1000000007;
  return x;
}
long long mul(long long a, long long b) {
  long long x = (a * b) % 1000000007;
  return x;
}
long long sub(long long a, long long b) {
  long long x = (a - b + 1000000007) % 1000000007;
  return x;
}
long long divi(long long a, long long b) {
  long long x = a;
  long long y = powermod(b, 1000000007 - 2, 1000000007);
  long long res = (x * y) % 1000000007;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  map<long long, long long> mpp;
  map<long long, long long>::iterator it;
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    if (mpp[x] < y) mpp[x] = y;
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    if (mpp[x] < y) mpp[x] = y;
  }
  long long sum = 0;
  for (it = mpp.begin(); it != mpp.end(); it++) {
    sum += it->second;
  }
  cout << sum;
  return 0;
}
