#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, t = 0, q;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    t += a;
  }
  cin >> q;
  int f = 0;
  int Ans = INT_MAX;
  while (q--) {
    int x, y;
    cin >> x >> y;
    if (f == 1) continue;
    if (x <= t && t <= y) {
      Ans = t;
      f = 1;
    } else if (x >= t) {
      f = 2;
      if (Ans > x) Ans = x;
    }
  }
  if (f == 0)
    cout << -1 << endl;
  else
    cout << Ans << endl;
  return 0;
}
