#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans = 0;
  int n, a = 0, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b;
    a += b;
  }
  int m, c, d;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> c >> d;
    if (ans == 0) {
      if (a >= c && a <= d) ans = a;
      if (c > a) ans = c;
    }
  }
  if (ans != 0)
    cout << ans;
  else
    cout << -1;
  return 0;
}
