#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T LCM(T a, T b) {
  return a * (b / gcd(a, b));
}
template <typename T>
T expo(T base, T e, T mod) {
  T res = 1;
  while (e > 0) {
    if (e & 1) res = res * base % mod;
    base = base * base % mod;
    e >>= 1;
  }
  return res;
}
template <typename T, typename second>
T expo(T b, second e) {
  if (e <= 1) return e == 0 ? 1 : b;
  return (e & 1) == 0 ? expo((b * b), e >> 1) : (b * expo((b * b), e >> 1));
}
template <typename T, typename second>
T modinv(T a, second mod) {
  return expo(a, mod - 2, mod);
}
template <typename T>
void in(T &x) {
  T c = getchar();
  while (((c < 48)(c > 57)) && (c != '-')) c = getchar();
  bool neg = false;
  if (c == '-') neg = true;
  x = 0;
  for (; c < 48 || c > 57; c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) x = (x * 10) + (c - 48);
  if (neg) x = -x;
}
int main() {
  long n, m;
  long sm = 0;
  cin >> n;
  long a[n];
  for (__typeof(n) i = 0; i < n; i++) {
    cin >> a[i];
    sm += a[i];
  }
  cin >> m;
  int s[m], e[m];
  for (__typeof(m) i = 0; i < m; i++) cin >> s[i] >> e[i];
  long i = 0, ans = -1;
  if (m == 0 || sm > e[m - 1]) {
    cout << -1;
    return 0;
  }
  if (sm <= s[0]) {
    cout << s[0];
    return 0;
  }
  while (i < m) {
    if (sm >= s[i] && sm <= e[i]) {
      cout << sm;
      break;
    } else if (sm > e[i] && sm <= s[i + 1]) {
      cout << s[i + 1];
      break;
    } else
      i++;
  }
  return 0;
}
