#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  int b[a], c = 0;
  for (int i = 0; i < a; i++) {
    cin >> b[i];
    c += b[i];
  }
  int d;
  cin >> d;
  int e[d], f[d];
  for (int i = 0; i < d; i++) {
    cin >> e[i] >> f[i];
    if (c <= e[i]) {
      cout << e[i];
      return 0;
    } else {
      if (c <= f[i]) {
        cout << c << endl;
        return 0;
      }
    }
  }
  cout << "-1" << endl;
  return 0;
}
