#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, tmp;
  int sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    sum += tmp;
  }
  int a[1000] = {0}, b[1000] = {0};
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
  }
  int moment = 0;
  for (int i = 0; i < m; i++) {
    if (b[i] >= sum) {
      moment = sum > a[i] ? sum : a[i];
      break;
    }
  }
  if (moment == 0)
    cout << -1;
  else
    cout << moment;
  return 0;
}
