#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, m;
  cin >> n;
  long long int a[n];
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  cin >> m;
  long long int x, y;
  for (long long int i = 0; i < m; i++) {
    cin >> x >> y;
    if (y >= sum) {
      cout << max(x, sum) << "\n";
      return 0;
    }
  }
  cout << -1 << "\n";
}
