#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int a[N];
struct str {
  int l, r;
} b[N];
bool cmp(str x, str y) { return x.l < y.l; }
int main() {
  int n, m;
  scanf("%d", &n);
  int s = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    s += a[i];
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &b[i].l, &b[i].r);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1, cmp);
  if (s > b[m].r) {
    cout << -1 << endl;
    return 0;
  }
  int ans = -1;
  for (int i = 1; i <= m; i++)
    if (s >= b[i].l && s <= b[i].r) {
      ans = s;
      break;
    }
  if (ans == -1) {
    for (int i = 1; i <= m; i++)
      if (b[i].l > s) {
        ans = b[i].l;
        break;
      }
  }
  cout << ans << endl;
  return 0;
}
