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