#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k, n, m, s = 0;
  int a[1008], lj[1008], rj[1008];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
  }
  cin >> m;
  if (m != 0) {
    for (i = 0; i < m; i++) {
      cin >> lj[i] >> rj[i];
    }
  }
  if (m == 0) {
    cout << -1 << endl;
    exit(0);
  }
  if (lj[0] > s) {
    cout << lj[0] << endl;
    exit(0);
  }
  for (i = 0; i < m; i++) {
    if (rj[i] >= s && lj[i] <= s) {
      cout << s << endl;
      exit(0);
    }
    if (i >= 1) {
      if (rj[i - 1] <= s && lj[i] >= s) {
        cout << lj[i] << endl;
        exit(0);
      }
    }
    if (i == m - 1 && rj[i] < s) {
      cout << -1 << endl;
      exit(0);
    }
  }
  return 0;
}
