#include <bits/stdc++.h>
using namespace std;
int n, m;
string s;
int main() {
  cin >> n;
  int x, s = 0;
  for (int i = 0; i < n; i++) cin >> x, s += x;
  int m;
  cin >> m;
  int ans = 1e9;
  for (int i = 1; i <= m; i++) {
    int t1, t2;
    cin >> t1 >> t2;
    if (s >= t1 && s <= t2) {
      cout << s;
      return 0;
    }
    if (s <= t2) {
      ans = min(ans, t1);
    }
  }
  if (ans == 1e9) {
    cout << -1;
  } else
    cout << ans;
}
