#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> m1;
long long int n, l, r, q;
long long int a1[1010101];
int main() {
  cin >> n;
  for (long long int i = 0; i < n; i += 1) cin >> a1[i];
  cin >> q;
  for (long long int i = 0; i < q; i += 1) {
    cin >> l >> r;
    for (long long int i = l; i <= r; i += 1) {
      m1[i] += 1;
    }
  }
  long long int p = 0;
  for (long long int i = 0; i < n; i += 1) {
    p += a1[i];
  }
  for (long long int i = p; i <= 100000; i += 1) {
    if (m1[i]) {
      cout << i << "\n";
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}
