#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;
vector<int> arr[1000000];

int main(){
	fop;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) 
		scanf("%d", &a[i]);
	scanf("%d", &m);
	assert(n <= 1000 && m <= 1000);
	for (int i = 1; i <= m; ++i) { 
		scanf("%d%d", &l, &r);
		arr[l].pb(r);
	}	
	int ans = 0;
	set<pi> q;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < arr[i].size(); ++j)
			q.insert(mp(-arr[i][j], was[arr[i][j]]++));		
		while (q.size() > a[i]) 
			q.erase(*(q.begin())), ++ans;
		while (was[i] >= 0)
			q.erase(mp(-i, --was[i]));					
	}
	printf("%d", ans);		
	return 0;
}