#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  return b == 0 ? abs(a) : gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int prime[1000000];
void seive() {
  int n_prime = 1000000;
  fill_n(prime, n_prime, 1);
  prime[0] = 0;
  prime[1] = 0;
  for (int i = 2; i * i <= n_prime; i++) {
    if (prime[i]) {
      for (int j = i * i; j <= n_prime; j += i) {
        prime[j] = 0;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  std::cin >> n;
  int temp = 0, tim = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> temp;
    tim = tim + temp;
  }
  int m;
  std::cin >> m;
  int x, y;
  int con = 0;
  for (int i = 0; i < m; i++) {
    std::cin >> x >> y;
    if (x <= tim && y >= tim && con == 0) {
      temp = tim;
      con = 1;
    } else if (tim < x && con == 0) {
      temp = x;
      con = 1;
    }
  }
  if (con == 0) {
    std::cout << -1 << '\n';
    return 0;
  }
  std::cout << temp << '\n';
  return 0;
}
