#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int i, a[n], j, s = 0, s1 = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    s = s + a[i];
  }
  int m, k = 0;
  cin >> m;
  if (m > 0) {
    int l[m], r[m];
    for (i = 0; i < m; i++) cin >> l[i] >> r[i];
    for (i = 0; i < n; i++) {
      if (s1 <= r[m - 1] && a[0] <= r[m - 1]) s1 = s1 + a[i];
    }
    if (s == s1) {
      for (i = 0; i < m; i++) {
        if (s1 >= l[i] && s1 <= r[i]) {
          k = s1;
          break;
        } else {
          if (l[i] > s1) {
            k = l[i];
            break;
          }
        }
      }
      cout << k;
    } else
      cout << -1;
  } else
    cout << -1;
  return 0;
}
