#include <bits/stdc++.h>
using namespace std;
long long n, a, m, l, r, ans, cnt;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    ans += a;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    if (ans <= r) {
      cout << max(l, ans);
      exit(0);
    }
  }
  cout << -1;
}
