#include <bits/stdc++.h>
using namespace std;
const long long int MX = 2000005;
const long long int mod = 1e9 + 7;
const long long int inf = 1LL << 62;
int dx4[] = {0, 0, -1, 1};
int dy4[] = {1, -1, 0, 0};
int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
int dy[] = {1, 0, -1, 1, -1, 1, 0, -1};
long long int ar[MX];
pair<long long int, long long int> br[MX];
int main() {
  long long int t, i, j, sum = 0, cnt = 0, mx = 0, mn = inf, x, y, a, b, c, n,
                         m, q, k;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ar[i], sum += ar[i];
  cin >> m;
  for (int i = 1; i <= m; i++) cin >> br[i].first >> br[i].second;
  for (int i = 1; i <= m; i++) {
    if (sum <= br[i].second) {
      cout << (max(br[i].first, sum)) << endl;
      return 0;
    }
  }
  cout << (-1) << endl;
  return 0;
}
