//	Mohib Manva
#include<bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define LOCAL 0
#define pb push_back
#define ll long long

ll po(ll a,ll b){
	ll x = 1,y=a;
	while(b>0){
		if(b%2){
			x = x*y;
			x %= mod;
		}
		y=y*y;
		y%=mod;
		b/=2;
	}
	return x;
}

static vector<int> adj[200005];

static int seg[1000005],lazy[1000005];
static int pre[200005],prez[200005];

void build(int s,int e,int ind){
	lazy[ind] = 1e8;
	if(s == e){
		if(s == 0){
			seg[ind] = 0;
		} else {
			seg[ind] = 1e8;
		}
		return;
	}
	int mi = (s+e)>>1;
	build(s,mi,2*ind+1);
	build(mi+1,e,2*ind+2);
	seg[ind] = min(seg[2*ind+1],seg[2*ind+2]);
	return;
}

void update(int s,int e,int ind,int qs,int qe,int val){
	if(lazy[ind] != 1e8){
		seg[ind] = min(seg[ind],lazy[ind]+prez[s]);
		if(s != e){
			lazy[2*ind+1] = min(lazy[2*ind+1],lazy[ind]);
			lazy[2*ind+2] = min(lazy[2*ind+2],lazy[ind]);
		}
		lazy[ind] = 1e8;
	}
	if(s > qe || e < qs){
		return;
	}
	if(qs <= s && e <= qe){
		seg[ind] = min(seg[ind],val+prez[s]);
		if(s != e){
			lazy[2*ind+1] = min(lazy[2*ind+1],val);
			lazy[2*ind+2] = min(lazy[2*ind+2],val);
		}
		return;
	}
	int mi = (s+e)>>1;
	update(s,mi,2*ind+1,qs,qe,val);
	update(mi+1,e,2*ind+2,qs,qe,val);
	seg[ind] = min(seg[2*ind+1],seg[2*ind+2]);
}

void update1(int s,int e,int ind,int qind,int val){
	if(lazy[ind] != 1e8){
		seg[ind] = min(seg[ind],lazy[ind]+prez[s]);
		if(s != e){
			lazy[2*ind+1] = min(lazy[2*ind+1],lazy[ind]);
			lazy[2*ind+2] = min(lazy[2*ind+2],lazy[ind]);
		}
		lazy[ind] = 1e8;
	}
	if(s > qind || e < qind){
		return;
	}
	if(s == e){
		seg[ind] = min(seg[ind],val);
		return;
	}
	int mi = (s+e)>>1;
	update1(s,mi,2*ind+1,qind,val);
	update1(mi+1,e,2*ind+2,qind,val);
	seg[ind] = min(seg[2*ind+1],seg[2*ind+2]);
	return;
}


int query(int s,int e,int ind,int qind){
	if(lazy[ind] != 1e8){
		seg[ind] = min(seg[ind],lazy[ind]+prez[s]);
		if(s != e){
			lazy[2*ind+1] = min(lazy[2*ind+1],lazy[ind]);
			lazy[2*ind+2] = min(lazy[2*ind+2],lazy[ind]);
		}
		lazy[ind] = 1e8;
	}
	if(qind > e || s > qind){
		return 1e8;
	}
	if(qind <= s && e <= qind){
		return seg[ind];
	}
	int mi = (s+e)>>1;
	return min(query(s,mi,2*ind+1,qind),query(mi+1,e,2*ind+2,qind));
}


int main(){
	if(LOCAL){
    	freopen("C:/Users/gold/Desktop/sublime IO/input.txt","r",stdin);
    	freopen("C:/Users/gold/Desktop/sublime IO/output.txt","w",stdout);
	}
	int T = 1;
	//scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		static int b[200005];
		for(int i=0;i<n;i++){
			scanf("%d",&b[i]);
		}
		for(int i=0;i<n;i++){
			pre[i+1] = b[i];
			pre[i+1] += pre[i];
			prez[i+1] = 1 - b[i];
			prez[i+1] += prez[i];
		}

		int q;
		scanf("%d",&q);
		for(int i=0;i<q;i++){
			int l,r;
			scanf("%d %d",&l,&r);
			adj[r].push_back(l);
		}
		static int dp[200005];
		dp[0] = 0;
		build(0,n,0);
		for(int i=1;i<=n;i++){
			dp[i] = query(0,n,0,i-1) + (b[i-1] == 1);
			for(int j=0;j<adj[i].size();j++){
				int l = adj[i][j];
				int r = i;
				int x = query(0,n,0,l-1);
				update(0,n,0,l,r,x-prez[l-1]);
				dp[i] = min(dp[i],x+prez[r]-prez[l-1]);
			}
			update1(0,n,0,i,dp[i]);
			//printf("dbg:%d %d\n",i,dp[i]);
		}
		printf("%d\n",dp[n]);
	}
	return 0;	
}

Measured memory_bytes: 20736