#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  int z;
  long long sum = 0;
  for (int i = 0; i < x; i++) {
    cin >> z;
    sum += z;
  }
  int y;
  cin >> y;
  int a = -1, b = -1;
  bool arr[100005] = {0};
  for (int i = 0; i < y; i++) {
    cin >> a >> b;
    for (int j = a; j <= b; j++) {
      arr[j]++;
    }
  }
  if (sum > b) {
    cout << -1;
    return 0;
  }
  for (int i = sum; i <= 100000; i++) {
    if (arr[i]) {
      cout << sum;
      return 0;
    }
    sum++;
  }
  cout << -1;
}
