#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int MAX = (int)1e3 + 5;
void build() { return; }
int n, m;
int store[MAX];
pair<int, int> store2[MAX];
void Init() {
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) scanf("%d", store + i);
  scanf("%d", &m);
  for (int i = 0; i < (m); ++i)
    scanf("%d %d", &store2[i].first, &store2[i].second);
  return;
}
void sol() {
  int cnt = 0;
  for (int i = 0; i < (n); ++i) cnt += store[i];
  for (int i = 0; i < (m); ++i) {
    if (cnt >= store2[i].first && cnt <= store2[i].second) {
      printf("%d", cnt);
      return;
    }
    if (store2[i].first > cnt) {
      printf("%d", store2[i].first);
      return;
    }
  }
  puts("-1");
  return;
}
int main(void) {
  Init();
  build();
  sol();
  return 0;
}
