#include <bits/stdc++.h>
using namespace std;
int arr[100001];
pair<int, int> val[100001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, i, j, k, l, r;
  cin >> n;
  k = 0;
  for (i = 0; i < n; ++i) cin >> arr[i], k += arr[i];
  cin >> m;
  int cur = 0, cnt = 0;
  j = 0;
  for (i = 0; i < m; ++i) {
    cin >> l >> r;
    if (r >= k) {
      cout << max(l, k) << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
