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