#include<iostream>
#include<cassert>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector> 
#include<cstring>
#include<set>
#include<string>
#define mp make_pair
#define scn second
#define frs first
#define pb push_back
#define NAME "toy"
#define fop freopen(NAME ".in", "r", stdin); freopen(NAME ".out", "w", stdout); 
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pi;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
int was[1000000], a[1000000], n, l, r, m, b[1000];
vector<pi> arr;

int main(){
	fop;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) 
		scanf("%d", &a[i]);
	scanf("%d", &m);
	for (int i = 0; i < m; ++i) { 
		scanf("%d%d", &l, &r);
		arr.pb(mp(l,r));
	}	
	assert(n <= 15 && m <= 15);
	int ans = 1000000;
	for (int i = 0; i < 1 << m; ++i) {
		for (int j = 1; j <= n; ++j)
			b[j] = 0;
		int cnt = 0;
		for (int j = 0; j < m; ++j) {
			if ((1 << j) & i) {
				for (int k = arr[j].frs; k <= arr[j].scn; ++k)
					++b[k];
			}
			else 
				++cnt;
		}
	    int f = 1;
	    for (int j = 1; j <= n; ++j)
	    	f &= b[j] <= a[j];
	    if (f)
	    	ans = min(ans, cnt);
		
	}
	
	
	printf("%d", ans);		
	return 0;
}