#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000];
bool ok = false;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int sum = 0;
  for (int i = 0; i < n; i++) sum += a[i];
  int m;
  cin >> m;
  int l, r;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    if (sum >= l && sum <= r) {
      cout << sum << endl;
      exit(0);
    }
    if (sum < l) cout << l << endl, exit(0);
  }
  cout << -1 << endl;
  return 0;
}
