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