#include <bits/stdc++.h>
using namespace std;
long long a[100007];
int main() {
  long long t, n, i, q, l, r, res;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  for (i = 2; i <= n; i++) a[i] += a[i - 1];
  cin >> q;
  i = 1;
  res = 0;
  while (q--) {
    cin >> l >> r;
    while (i <= n && a[i] <= r) {
      res = max(l, a[i]);
      i++;
    }
  }
  if (i > n)
    cout << res << endl;
  else
    cout << -1 << endl;
  return 0;
}
