#include <bits/stdc++.h>
using namespace std;
int tab[100005];
int main() {
  int n, c, x, a, b, tot = 0;
  vector<pair<int, int> > t;
  vector<int> v;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    tot += x;
  }
  cin >> c;
  for (int j = 0; j < c; j++) {
    cin >> a >> b;
    for (int i = a; i <= b; i++) tab[i] = 1;
  }
  for (int i = tot; i < 100005; i++) {
    if (tab[i] == 1) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
