#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
const long long oo = 1e18;
long long a[N], w[N], k, n, t, l[N], r[N], res;
string s;
vector<long long> b;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    t += a[i];
  }
  cin >> k;
  for (int i = 1; i <= k; ++i) cin >> l[i] >> r[i];
  sort(l + 1, l + 1 + k);
  sort(r + 1, r + 1 + k);
  int i = 0;
  for (i = k; i >= 1; --i) {
    if (l[i] <= t && t <= r[i])
      res = t;
    else if (r[i] < t)
      break;
  }
  if (res == 0 && i != k && k != 0)
    res = l[i + 1];
  else if (res == 0)
    res = -1;
  if (res == 0) res = -1;
  cout << res << "\n";
}
