#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
#define int long long
const int inf=0x3f3f3f3f3f3f3f3f;
int n,m,pre[200100][2],tree[1001000],ans,a[200100],f[200100],x,y;
vector<int>v[200100];
void modify(int t,int l,int r,int pos,int val){
	if(l==r){
		tree[t]=min(tree[t],val);
		return;
	}
	int mid=(l+r)/2;
	if(pos<=mid)modify(t*2,l,mid,pos,val);
	else modify(t*2+1,mid+1,r,pos,val);
	tree[t]=min(tree[t*2],tree[t*2+1]);
}
int query(int t,int l,int r,int L,int R){
	if(l>R||L>r)return inf;
	if(L<=l&&r<=R)return tree[t];
	int mid=(l+r)/2;
	return min(query(t*2,l,mid,L,R),query(t*2+1,mid+1,r,L,R));
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		pre[i][0]=pre[i-1][0]+(a[i]==0);
		pre[i][1]=pre[i-1][1]+(a[i]==1);
	}
	memset(f,0x3f,sizeof(f));
	scanf("%lld",&m);
	for(int i=1;i<=m;i++){
		scanf("%lld%lld",&x,&y);
		v[x].push_back(y);
	}
	f[0]=0;
	memset(tree,0x3f,sizeof(tree));
	for(int i=1;i<=n;i++){
		for(int j=0;j<v[i].size();j++){
			int now=v[i][j];
			int minn=min(f[i-1],query(1,1,n,max(i-1,1ll),now));
			if(minn<f[now]){
				f[now]=minn;
				modify(1,1,n,now,minn);
			}
		}
		f[i]=min(f[i],f[i-1]+((a[i]==1)?1:-1));
	}
	printf("%lld\n",f[n]+pre[n][0]);
}