#include <bits/stdc++.h>
using namespace std;
int n, ar[1111], vis[100069];
priority_queue<int> pq;
long long sum;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    sum += ar[i];
  }
  int m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) vis[j] = 1;
  }
  for (int i = sum; i <= 1e5; i++) {
    if (vis[i]) {
      cout << i << endl;
      return 0;
    }
  }
  puts("-1");
  return 0;
}
