#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return GCD(b, a % b);
  }
}
bool yoyo(const pair<long long, string> p1, const pair<long long, string> p2) {
  return p1.first > p2.first;
}
int main() {
  long long t, n, i, m, j, k, a, b, c, l = 0, r = 0, u = 0, mr, ml, md, mu;
  cin >> n;
  vector<long long> v1;
  long long d = 0, su = 0, fin;
  vector<pair<long long, long long> > vn;
  for (i = 0; i < n; i++) {
    cin >> a;
    v1.push_back(a);
    su += a;
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> l >> r;
    vn.push_back(make_pair(l, r));
    if (su >= l && su <= r) {
      d = 1;
      fin = su;
      break;
    }
    if (l > su) {
      fin = l;
      d = 1;
      break;
    }
  }
  if (d == 1)
    cout << fin;
  else
    cout << -1;
  return 0;
}
