#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(const vector<T> &a) {
  for (T x : a) cout << x << " ";
  cout << '\n';
}
const long long N = 1e5 + 50, oo = 1e18 + 500;
const long long mod = 998244353;
const long double eps = 1e-12, PI = 2 * acos(0.0);
long long n, m, k;
long long cnt = 0;
vector<long long> g[N];
vector<long long> rg[N];
vector<long long> visit(N, 0);
signed main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> k;
    cnt += k;
  }
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long l, r;
    cin >> l >> r;
    for (long long j = l; j <= r; j++) {
      visit[j]++;
    }
  }
  long long ans = cnt;
  while (ans < N) {
    if (visit[ans]) break;
    ans++;
  }
  if (ans >= N) {
    cout << -1;
  } else {
    cout << ans;
  }
}
