#include <bits/stdc++.h>
using namespace std;
const int s = 1e3 + 1;
const int x = 1e5 + 1;
int n, m;
pair<int, int> p[x];
int a[s];
int main() {
  cin >> n;
  int c = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  cin >> m;
  for (int i = 0; i < m; i++) cin >> p[i].first >> p[i].second;
  if (sum <= p[0].first) {
    cout << p[0].first << '\n';
    return 0;
  }
  for (int i = 0; i < m; i++) {
    if (sum >= p[i].first && sum <= p[i].second) {
      cout << sum << '\n';
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (sum < p[i].first) {
      cout << p[i].first << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
