#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15 + 9;
const long long N = 1e5 + 5;
long long A[N], n, k, B[N];
map<long long, long long> mm;
void solve() {
  long long i, j, x = 0, y = 1, m;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x >> y;
    mm[x] = max(mm[x], y);
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    mm[x] = max(mm[x], y);
  }
  x = 0;
  for (auto i : mm) x += i.second;
  cout << x;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1, i;
  while (t--) {
    solve();
  }
}
