#include <bits/stdc++.h>
using namespace std;
template <class T>
T min(T a, T b, T c) {
  return min(a, min(b, c));
}
template <class T>
T min(T a, T b, T c, T d) {
  return min(a, min(b, min(c, d)));
}
template <class T>
T max(T a, T b, T c) {
  return max(a, max(b, c));
}
template <class T>
T max(T a, T b, T c, T d) {
  return max(a, max(b, max(c, d)));
}
bool cmp(const int& a, const int& b) { return a > b; }
bool isCom[1000009];
int a[100007], s[1000009], _s[1000009];
int cnt[100007][207], __cnt[100007][207];
vector<int> nodes[400007];
void initMerge(int root, int left, int right) {
  if (left == right) {
    nodes[root].push_back(a[left]);
    return;
  }
  int mid = (left + right) / 2;
  initMerge(2 * root, left, mid);
  initMerge(2 * root + 1, mid + 1, right);
  nodes[root].resize(right - left + 1);
  merge(nodes[2 * root].begin(), nodes[2 * root].end(),
        nodes[2 * root + 1].begin(), nodes[2 * root + 1].end(),
        nodes[root].begin());
  return;
}
int queryMerge(int root, int left, int right, int i, int j, int x) {
  if (i > right || j < left) return 0;
  if (i <= left && right <= j)
    return nodes[root].end() -
           lower_bound(nodes[root].begin(), nodes[root].end(), x);
  int mid = (left + right) / 2;
  return queryMerge(2 * root, left, mid, i, j, x) +
         queryMerge(2 * root + 1, mid + 1, right, i, j, x);
}
int main() {
  int n;
  scanf("%d", &n);
  int ans = 0;
  for (int i = (1); i <= (n); ++i) {
    int x;
    scanf("%d", &x);
    ans += x;
  }
  int m;
  scanf("%d", &m);
  int res = 0;
  for (int i = (1); i <= (m); ++i) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (ans >= l && ans <= r) {
      printf("%d\n", ans);
      return 0;
    }
    if (l >= ans) {
      printf("%d\n", l);
      return 0;
    }
  }
  printf("%d\n", -1);
  return 0;
}
