#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    long long x;
    cin >> x;
    sum += x;
  }
  int M;
  cin >> M;
  if (M == 0) {
    cout << -1 << endl;
    return 0;
  }
  vector<pair<long long, long long> > periods;
  for (int i = 0; i < M; i++) {
    long long x, y;
    cin >> x >> y;
    periods.push_back(make_pair(x, y));
  }
  if (periods[M - 1].second < sum) {
    cout << -1 << endl;
    return 0;
  }
  if (sum < periods[0].first) {
    cout << periods[0].first << endl;
    return 0;
  }
  for (int i = 0; i < M; i++) {
    if (sum >= periods[i].first && sum <= periods[i].second) {
      cout << sum << endl;
      return 0;
    }
    if (i > 0) {
      if (sum > periods[i - 1].second && sum < periods[i].first) {
        cout << periods[i].first << endl;
        return 0;
      }
    }
  }
  return 0;
}
