#include <bits/stdc++.h>
using namespace std;
bool A[100001];
int main() {
  ios::sync_with_stdio(0);
  int n, m, l, r, x, second = 0;
  cin >> n;
  for (int i = 0; i < (int)n; i++) cin >> x, second += x;
  cin >> m;
  for (int i = 0; i < (int)m; i++) {
    cin >> l >> r;
    for (int j = l; j < r + 1; j++) A[j] = true;
  }
  if (second > 1e5) {
    cout << -1;
    return 0;
  }
  for (int i = second; i < 100001; i++) {
    if (A[i]) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1;
}
