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