#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int a[maxn], l[maxn], r[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  int n, m, tot = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), tot += a[i];
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) scanf("%d%d", &l[i], &r[i]);
  int ret = 0x7fffffff;
  for (int i = 1; i <= m; ++i) {
    if (tot <= r[i] && tot >= l[i]) ret = min(tot, ret);
    if (tot <= r[i] && tot < l[i]) ret = min(ret, l[i]);
  }
  if (ret == 0x7fffffff)
    printf("-1\n");
  else
    printf("%d\n", ret);
  return 0;
}
