#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  map<int, bool> ci;
  int m;
  cin >> m;
  int x, y;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    for (int j = x; j <= y; j++) ci[j] = true;
  }
  for (int i = sum; i < 123456; i++) {
    if (ci[i]) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
