#include <bits/stdc++.h>
using namespace std;
const int MX = 3 * 1e5 + 10;
const double PI = acos(-1.0), EPS = 1e-9;
long long N, M, k;
pair<int, int> p[2000];
int arr[2000];
bool vis[MX];
vector<int> bb;
int main() {
  cin >> N;
  long long sum = 0;
  for (int i = 0; i < N; i++) cin >> arr[i], sum += arr[i];
  cin >> M;
  for (int i = 0; i < M; i++) {
    cin >> p[i].first >> p[i].second;
  }
  long long ans = -1;
  for (int i = 0; i < M; i++) {
    if (p[i].first <= sum && p[i].second >= sum) {
      ans = sum;
      break;
    }
    if (p[i].first >= sum) {
      ans = p[i].first;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}
