#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
int MAXNUM = 5e3 + 5;
vector<int> vis(MAXNUM);
vector<int> pr;
void sieve() {
  pr.push_back(2);
  for (long long i = 3; i < MAXNUM; i += 2)
    if (!vis[i]) {
      pr.push_back(i);
      for (long long j = i * i; j < MAXNUM; j += 2 * i) vis[j] = true;
    }
}
void solve() {
  long long n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    sum += x;
  }
  long long t = -1;
  long long m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    long long l, r;
    cin >> l >> r;
    if (t == -1) {
      if (sum < l)
        t = l;
      else if (sum <= r)
        t = sum;
    }
  }
  cout << t << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
