#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vlli = vector<long long int>;
using vpii = vector<pair<int, int>>;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lli n, m, x, y, ans = 0;
  map<lli, lli> val;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> x >> y, val[x] = max(val[x], y);
  cin >> m;
  for (int i = 0; i < m; i++) cin >> x >> y, val[x] = max(val[x], y);
  for (auto i : val) ans += i.second;
  cout << ans;
}
