#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &i : a) cin >> i;
  int m;
  cin >> m;
  vector<int> l(m), r(m);
  for (int i = 0; i < m; ++i) cin >> l[i] >> r[i];
  int s = accumulate(begin(a), end(a), 0);
  for (int i = 0; i < m; ++i)
    if (s >= l[i] && s <= r[i])
      return cout << s, 0;
    else if (l[i] > s)
      return cout << l[i], 0;
  cout << -1;
  return 0;
}
