#include <bits/stdc++.h>
using namespace std;
void printarr(int arr[], int n) {
  for (int i = 0; i < n; ++i) cerr << arr[i] << (i < n - 1 ? ' ' : '\n');
}
template <typename T>
void printv(T &a) {
  for (auto it = a.begin(); it != a.end(); ++it) cerr << *it << ' ';
  cerr << '\n';
}
long long int ans;
int arr[300009];
void solve() {
  bool ok = false;
  int n, m, k;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum += arr[i];
  }
  ans = -1;
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    if (min(r, sum) == sum && !ok) ans = max(sum, l), ok = true;
  }
  cout << ans;
  cout << '\n';
}
void sol() {}
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
int main() {
  fastio();
  solve();
  return 0;
}
