#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, o, k, q, a[100001];
void w() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
void YoN(bool bol) {
  if (bol)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return;
}
void CO(int bol) {
  cout << bol << endl;
  return;
}
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> o;
    q += o;
  }
  cin >> n;
  k = -1;
  for (i = 1; i <= n; i++) {
    cin >> o >> j;
    if (o <= q && q <= j && k == -1) k = q;
    if (q < o && k == -1) k = o;
  }
  cout << k << endl;
}
