#include <bits/stdc++.h>
using namespace std;
long long x, y, sum = 0;
int n, m;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &x);
    sum += x;
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    scanf("%lld%lld", &x, &y);
    if (sum >= x && sum <= y) {
      return printf("%lld\n", sum), 0;
    } else if (sum < x) {
      return printf("%lld\n", x), 0;
    }
  }
  return printf("-1\n"), 0;
  return 0;
}
