#include <bits/stdc++.h>
using namespace std;
const int K = 40;
const long long md = 1e9 + 7;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int t = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    t += x;
  }
  int m;
  cin >> m;
  int min_time = 2e9;
  while (m--) {
    int l, r;
    cin >> l >> r;
    if (t <= r) {
      min_time = min(min_time, max(t, l));
    }
  }
  if (min_time == (int)2e9) {
    cout << "-1\n";
  } else {
    cout << min_time << "\n";
  }
  return 0;
}
