#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    sum += x;
  }
  int m;
  cin >> m;
  long long l[m], r[m];
  for (int i = 0; i < m; i++) cin >> l[i] >> r[i];
  long long ans = -1;
  for (int i = 0; i < m; i++) {
    if (sum <= r[i] && sum >= l[i]) {
      ans = sum;
      break;
    } else if (sum < l[i]) {
      ans = l[i];
      break;
    }
  }
  cout << ans;
  return 0;
}
