#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,ans,f[1000010],id[500010],lz[1000010],a[500010],b[500010];
vector<int>zh[500010];
void build(int x,int l,int r){
	if(l==r){
		if(l==0)f[x]=0;
		 else f[x]=-1e8;
		return;
	}
	int mid=(l+r)/2;
	build(x*2,l,mid);build(x*2+1,mid+1,r);
	f[x]=max(f[x*2],f[x*2+1]);
}
void pushdown(int x){
	if(lz[x]){
		lz[x*2]+=lz[x];lz[x*2+1]+=lz[x];
		f[x*2]+=lz[x];f[x*2+1]+=lz[x];
		lz[x]=0;
	}
}
void ins(int x,int l,int r,int t,int k,int w){
	if(l==t&&r==k){
		f[x]+=w;lz[x]+=w;
		return;
	}
	int mid=(l+r)/2;
	pushdown(x);
	if(mid>=k)ins(x*2,l,mid,t,k,w);
	 else if(t>mid)ins(x*2+1,mid+1,r,t,k,w);
	  else ins(x*2,l,mid,t,mid,w),ins(x*2+1,mid+1,r,mid+1,k,w);
	f[x]=max(f[x*2],f[x*2+1]);
}
void xiu(int x,int l,int r,int t,int w){
	if(l==r){
		f[x]=max(f[x],w);
		return;
	}
	int mid=(l+r)/2;
	pushdown(x);
	if(mid>=t)xiu(x*2,l,mid,t,w);
	 else xiu(x*2+1,mid+1,r,t,w);
	f[x]=max(f[x*2],f[x*2+1]);
}
int query(int x,int l,int r,int t,int k){
	if(l==t&&r==k)return f[x];
	pushdown(x);
	int mid=(l+r)/2;
	if(mid>=k)return query(x*2,l,mid,t,k);
	 else if(t>mid)return query(x*2+1,mid+1,r,t,k);
	  else return max(query(x*2,l,mid,t,mid),query(x*2+1,mid+1,r,mid+1,k));
}
//void get(int x,int l,int r,int t,int k)
int main(){
	int i,j,xlh,x;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&x);
		id[i]=x;
		if(x==1)b[i]=1;
		b[i]+=b[i-1];
	}
	scanf("%d",&m);
	for(i=1;i<=m;i++){
		scanf("%d%d",&x,&a[i]);
		zh[x].push_back(i);
	}
	build(1,0,n);
	for(i=1;i<=n;i++){
		//ins(1,0,n,0,i-1,(id[i]==0));
	//	printf("%d %d\n",i,query(1,0,n,0,i-1));
		for(j=0;j<zh[i].size();j++){
			x=zh[i][j];
			x=a[x];
			xlh=query(1,0,n,i,x)+b[x];
			xlh=max(xlh,query(1,0,n,0,i-1)+b[x]-b[i-1]);
			//printf("%d %d %d\n",i,x,xlh);
			xiu(1,0,n,x,xlh-b[x]);
		}
		ins(1,0,n,0,i-1,(id[i]==0));
		ins(1,0,n,i,i,b[i]);
		//ans=max(ans,f[1]);
	}
	ans=f[1];
	printf("%d",n-ans);
}