#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  long int sum = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  cin >> m;
  int l[m], r[m];
  for (int i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
  }
  bool check = false;
  int value;
  for (int i = 0; i < m; i++) {
    if (sum <= r[i] && sum >= l[i]) {
      check = true;
      break;
    }
  }
  if (check == true) {
    cout << sum;
  } else if (check == false) {
    for (int i = 0; i < m; i++) {
      if (sum <= l[i]) {
        check = true;
        value = l[i];
        break;
      }
    }
    if (check == true) {
      cout << value;
    }
    if (check == false) {
      cout << "-1";
    }
  }
  return 0;
}
