#include <bits/stdc++.h>
using namespace std;
struct _nl {
} nl;
bool _ns = 0;
template <typename T>
void _p(const T& _) {
  if constexpr (is_same<T, _nl>()) {
    cout << "\n";
    _ns = 0;
  } else {
    if (_ns) cout << " ";
    cout << _;
    _ns = 1;
  }
}
template <typename... T>
void out(const T&... _) {
  (_p(_), ...);
}
int ii() {
  int _;
  cin >> _;
  return _;
}
vector<int> ia(int n) {
  auto v = vector<int>(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  return v;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  auto n = ii();
  auto d = ia(n);
  auto sum = accumulate(d.begin(), d.end(), 0);
  auto ans = INT_MAX;
  int _nTests = ii();
  while (_nTests--) {
    auto l = ii();
    auto r = ii();
    if (l <= sum && r >= sum)
      ans = sum;
    else if (l > sum)
      ans = min(ans, l);
  }
  if (ans == INT_MAX)
    out(-1, nl);
  else
    out(ans, nl);
  return 0;
}
