#include <bits/stdc++.h>
const int MOD = 1000000007;
const int MAXN = 1000000001;
const double PI = 3.14159265359;
using namespace std;
pair<int, int> q[1001];
int main() {
  int n, m, a, z = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    z += a;
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    cin >> q[i].first >> q[i].second;
  }
  for (int i = 0; i < m; ++i) {
    if (q[i].second >= z) {
      cout << max(q[i].first, z);
      return 0;
    }
  }
  cout << -1;
  return 0;
}
