#include <bits/stdc++.h>
int fgpi() {
  int result = 0, ch;
  while (!isdigit(ch = getchar()))
    ;
  do result = (result << 3) + (result << 1) + (ch - '0');
  while (isdigit(ch = getchar()));
  return result;
}
int main() {
  int n = fgpi();
  int total = 0, ans = -1;
  while (n--) {
    total += fgpi();
  }
  n = fgpi();
  while (n--) {
    int start = fgpi();
    int end = fgpi();
    if (start >= total) {
      ans = start;
      break;
    } else if (end >= total) {
      ans = total;
      break;
    }
  }
  printf("%d", ans);
  return 0;
}
