#include <bits/stdc++.h>
using namespace std;
int main() {
  bool found = false;
  int n, m, l, r, sum = 0, num, Answer = -1;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> num, sum = sum + num;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    if (sum >= l && sum <= r && found == false)
      Answer = sum, found = true;
    else if (l > sum && found == false)
      Answer = l, found = true;
  }
  cout << Answer << endl;
}
