#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, m, r, l, sum = 0, sum1 = 0, j = 0;
  vector<int> a, b, c;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> r;
    a.push_back(r);
  }
  sort(a.begin(), a.end());
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> r;
    b.push_back(r);
    cin >> r;
    c.push_back(r);
  }
  if (m == 0)
    cout << "-1";
  else if (m == 1) {
    int sum2 = 0;
    for (int i = 0; i < n; i++) sum = sum + a[i];
    if (sum <= c[0] && sum >= b[0])
      cout << sum;
    else if (sum < b[0])
      cout << b[0];
    else
      cout << "-1";
  } else {
    for (i = 0; i < n; i++) {
      sum1 = sum1 + a[i];
      for (l = j; l < m; l++) {
        if (sum1 >= b[l] && sum1 <= c[l]) {
          sum = sum1;
          break;
        } else if (sum1 < b[l]) {
          sum = b[l];
          break;
        }
      }
      j = l;
    }
    if (sum1 <= c[m - 1])
      cout << sum;
    else
      cout << "-1";
  }
}
