#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, to = 0;
  cin >> n;
  int t[n];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
    to += t[i];
  }
  int m;
  cin >> m;
  int a;
  vector<pair<int, int> > v(m);
  for (int i = 0; i < m; i++) {
    cin >> a;
    v[i].first = a - to;
    cin >> a;
    v[i].second = a - to;
  }
  int f = 0;
  for (int i = 0; i < m; i++) {
    if (v[i].first >= 0) {
      cout << v[i].first + to << "\n";
      f = 1;
      break;
    }
    if (v[i].first < 0 && v[i].second >= 0) {
      cout << to << "\n";
      f = 1;
      break;
    }
  }
  if (f == 0) {
    cout << -1 << "\n";
  }
  return 0;
}
