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