#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int suf[200011];
int a[200011];
vector<pair<int,int> > adj[200011];
int dp[200011];
vi st[800011];
vector<ii> val[800011];

int sum(int l, int r)
{
	if(l==0) return dp[r];
	else return dp[r]-dp[l-1];
}

vector<ii> interval;

void modify(int id, int p, int value) {  // set value at position p
	int n=st[id].size()/2;
  for (st[id][p += n] = value; p > 1; p >>= 1) st[id][p>>1] = min(st[id][p], st[id][p^1]);
}

int ask(int id, int l, int r) {  // sum on interval [l, r)
	if(l>=r) return int(1e9);
  int res = int(1e9);
  int n=st[id].size()/2;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l&1) res = min(res, st[id][l++]);
    if (r&1) res = min(res, st[id][--r]);
  }
  return res;
}

int build(int id, int l, int r)
{
	if(r-l<2)
	{
		////cerr<<"BUILD : "<<id<<' '<<sum<<'\n';
		val[id].pb(mp(interval[l].se,l));
		st[id].assign(2,int(1e9));
		return 1;
	}
	int mid=(l+r)>>1;
	int sum = build(id*2,l,mid) + build(id*2+1,mid,r);
	for(int j=0;j<val[id*2].size();j++) val[id].pb(val[id*2][j]);
	for(int j=0;j<val[id*2+1].size();j++) val[id].pb(val[id*2+1][j]);
	sort(val[id].begin(),val[id].end());
	st[id].assign(2*sum,int(1e9));
	assert(val[id].size()==sum);
	////cerr<<"BUILD : "<<id<<' '<<sum<<'\n';
	return sum;
}

void update(int id, int l, int r, int pos, int v)
{
	if(pos>=r||pos<l) return ;
	int R = interval[pos].se;
	int poss=lower_bound(val[id].begin(),val[id].end(),mp(R,pos))-val[id].begin();
	////cerr<<id<<' '<<l<<' '<<r<<' '<<val[id].size()<<'\n';
	assert(poss>=0&&poss<int(val[id].size()));
	modify(id,poss,v);
	if(r-l<2) return ;
	int mid=(l+r)>>1;
	update(id*2,l,mid,pos,v); update(id*2+1,mid,r,pos,v);
}

int query(int id, int l, int r, int ql, int qr, int v)
{
	if(l>=qr||ql>=r) return int(1e9);
	if(ql<=l&&r<=qr)
	{
		int poss=lower_bound(val[id].begin(),val[id].end(),mp(v+1,-1))-val[id].begin();
		return ask(id,poss,int(st[id].size())/2);
	}
	int mid=(l+r)>>1;
	return min(query(id*2,l,mid,ql,qr,v),query(id*2+1,mid,r,ql,qr,v));
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	dp[0]=(a[0]==0);
	for(int i=1;i<n;i++)
	{
		dp[i]=dp[i-1]+(a[i]==0);
	}
	int q; cin>>q;
	for(int i=0;i<q;i++)
	{
		int l,r; cin>>l>>r;
		l--; r--;
		interval.pb(mp(l,r));
	}
	suf[n]=0;
	sort(interval.begin(),interval.end());
	for(int i=q-1;i>=0;i--)
	{
		adj[interval[i].fi].pb(mp(interval[i].se,i));
	}
	for(int i=0;i<n;i++)
	{
		sort(adj[i].rbegin(),adj[i].rend());
	}
	build(1,0,q);
	for(int i=n-1;i>=0;i--)
	{
		suf[i]=suf[i+1]+(a[i]==1);
		for(int j=0;j<adj[i].size();j++)
		{
			int r=adj[i][j].fi;
			int add=(i-1>=0?-dp[i-1]:0);
			int z=lower_bound(interval.begin(),interval.end(),mp(r+1,0))-interval.begin();
			z--;
			//test from interval
			int cur = add + query(1,0,q,adj[i][j].se+1,z+1,r); //must be more than r
			cur=min(cur,suf[r+1]+sum(i,r));
			suf[i]=min(suf[i],cur);
			//cerr<<i<<' '<<r<<' '<<cur<<"  "<<adj[i][j].se<<'\n';
			//cerr<<"UPDATE : "<<adj[i][j].se<<' '<<cur+add<<'\n';
			update(1,0,q,adj[i][j].se,cur-add);
		}
		//cerr<<"SUF "<<i<<" : "<<suf[i]<<'\n';
	}
	cout<<suf[0]<<'\n';
}


Measured memory_bytes: 132464