#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 24;
const int M = 2e5 + 10;
const int MAX = 1e6 + 24;
const int MOD = 1000 * 1000 * 1000 + 7;
const int inf = 1 << 28;
const double EPS = 1e-9;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0};
const int dx[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
          dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long INF = 1e18;
set<char> vowel = {'A', 'O', 'Y', 'E', 'U', 'I', 'a', 'o', 'y', 'e', 'u', 'i'};
long double dist(long double x, long double y, long double a, long double b) {
  return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
void prime(int primes[]) {
  for (int k = 0; k < 100001; k++) {
    primes[k] = 1;
  }
  primes[1] = 0;
  for (int k = 2; k < 100001; k++) {
    if (primes[k]) {
      for (int j = 2 * k; j < 100001; j += k) {
        primes[j] = 0;
      }
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long i = 0;
  map<long long, long long> m;
  long long n;
  cin >> n;
  for (int l = 0; l < n; l++) {
    long long x, y;
    cin >> x >> y;
    m[x] = y;
  }
  long long k;
  cin >> k;
  for (int l = 0; l < k; l++) {
    long long x, y;
    cin >> x >> y;
    m[x] = max(m[x], y);
  }
  for (auto u : m) i += u.second;
  cout << i;
  return 0;
}
