#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;
int n, a[N];
void code() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int sum = accumulate(a, a + n, 0ll);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (x > sum) {
      cout << x << "\n";
      return;
    }
    if (x <= sum and sum <= y) {
      cout << sum << "\n";
      return;
    }
  }
  cout << "-1\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  while (t-- > 0) {
    code();
  }
}
