#include <bits/stdc++.h>
using namespace std;
int n, m;
int so[20000];
int ti[200005];
int sum;
int main() {
  scanf("%d", &n);
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &so[i]);
    sum += so[i];
  }
  sort(so + 1, so + 1 + n);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    for (int j = a; j <= b; j++) ti[j] = 1;
    mx = max(mx, b);
  }
  if (mx < sum) {
    printf("-1");
    return 0;
  }
  for (int i = sum; i <= mx; i++) {
    if (ti[i] == 1) {
      printf("%d", i);
      return 0;
    }
  }
  return 0;
}
