#include <bits/stdc++.h>
using namespace std;
int binarySearch(int x, vector<pair<int, int> >& a, int start, int end) {
  if (start >= end) {
    if (x <= a[start].first)
      return a[start].first;
    else if (x <= a[start].second)
      return x;
    else
      return -1;
  }
  int mid = (start + end) / 2;
  pair<int, int> elem = a[mid];
  if (x >= elem.first && x <= elem.second) {
    return x;
  } else {
    if (mid > 0 && x < elem.first && x > a[mid - 1].second) {
      return elem.first;
    }
    if (x < elem.second) {
      return binarySearch(x, a, start, mid - 1);
    } else {
      return binarySearch(x, a, mid + 1, end);
    }
  }
}
int binarySearch(int x, vector<pair<int, int> >& a) {
  return binarySearch(x, a, 0, a.size() - 1);
}
int main() {
  int n, m;
  cin >> n;
  int sum = 0;
  int elem;
  for (int i = 0; i < n; i++) {
    cin >> elem;
    sum += elem;
  }
  cin >> m;
  if (m == 0) {
    cout << -1 << endl;
    return 0;
  }
  vector<pair<int, int> > b(m);
  for (int i = 0; i < m; i++) {
    pair<int, int> p;
    cin >> p.first >> p.second;
    b[i] = p;
  }
  cout << binarySearch(sum, b) << endl;
  return 0;
}
