//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}


const int N = 200004;
int n, arr[N], cnt[2][N], tree[4*N], lazy[4*N], DP[N];
vector<int> qarr[N];
vector<ii> pending;


void build(int node, int s, int e){
	if(s > e)	return;
	lazy[node] = MOD;
	if(s == e){
		tree[node] = MOD;
		return;
	}
	int mid = (s+e)/2;
	build(LEFT(node), s, mid);
	build(RIGHT(node), mid+1, e);
	tree[node] = min(tree[LEFT(node)], tree[RIGHT(node)]);
	tree[node] = min(tree[LEFT(node)], tree[RIGHT(node)]);
}


void update(int node, int s, int e, int lo, int hi, int val){
	if(lo > hi || s > e)	return;
	if(lazy[node] != MOD){
		tree[node] = min(tree[node], lazy[node]);
		if(s != e){
			lazy[LEFT(node)] = min(lazy[LEFT(node)], lazy[node]);
			lazy[RIGHT(node)] = min(lazy[RIGHT(node)], lazy[node]);
		}
		lazy[node] = MOD;
	}
	if(hi < s || lo > e)	return;
	if(s >= lo && e <= hi){
		tree[node] = min(tree[node], val);
		if(s != e){
			lazy[LEFT(node)] = min(lazy[LEFT(node)], val);
			lazy[RIGHT(node)] = min(lazy[RIGHT(node)], val);
		}
		return;
	}
	int mid = (s+e)/2;
	update(LEFT(node), s, mid, lo, hi, val);
	update(RIGHT(node), mid+1, e, lo, hi, val);
	tree[node] = min(tree[LEFT(node)], tree[RIGHT(node)]);
	tree[node] = min(tree[LEFT(node)], tree[RIGHT(node)]);
}



int query(int node, int s, int e, int pos){
	if(s > e)	return MOD;
	if(lazy[node] != MOD){
		tree[node] = min(tree[node], lazy[node]);
		if(s != e){
			lazy[LEFT(node)] = min(lazy[LEFT(node)], lazy[node]);
			lazy[RIGHT(node)] = min(lazy[RIGHT(node)], lazy[node]);
		}
		lazy[node] = MOD;
	}
	if(pos < s || pos > e)	return MOD;
	if(s == e)	return tree[node];
	int mid = (s+e)/2;
	return min(query(LEFT(node), s, mid, pos), query(RIGHT(node), mid+1, e, pos));
}


 
int main(){
 
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);

    scanf("%d", &n);
    for(int i=1;i<=n;i++)
    	scanf("%d", &arr[i]);
    arr[++n] = 1;
    for(int i=1;i<=n;i++){
    	cnt[0][i] = cnt[0][i-1];
    	cnt[1][i] = cnt[1][i-1];
    	cnt[arr[i]][i]++;
    }

    build(1, 1, n);
    DP[n] = 0;

    int q;
    scanf("%d", &q);
    while(q--){
    	int l, r;
    	scanf("%d%d", &l, &r);
    	qarr[l].pb(r);
    }

    for(int i=n-1;i>=1;i--){

    	DP[i] = DP[i+1] + (arr[i] == 1);
    	pending.clear();
    	for(auto r : qarr[i]){

    		if(r == i){
    			int temp = (arr[i] == 0) + DP[i+1];
    			DP[i] = min(DP[i], temp);
    			pending.pb({r, temp + cnt[0][i-1]});
    			continue;
    		}

// if(i == 6){
// 	cout<<"wtf "<<r<<" "<<cnt[0][r]-cnt[0][i-1]<<" "<<query(0, 1, 1, n, r+1, n)<<" "<<cnt[1][r]<<endl;;
// 	for(int j=8;j<=10;j++)	cout<<j<<" gives "<<query(0, 1, 1, n, j, j)<<endl;
// }

    		int temp = (cnt[0][r]-cnt[0][i-1]) + DP[r+1];
    		temp = min(temp, query(1, 1, n, r) - cnt[0][i-1]);
    		pending.pb({r, temp + cnt[0][i-1]});

    		DP[i] = min(DP[i], temp);
    	}

    	for(auto it : pending){
    		update(1, 1, n, i, it.ff, it.ss);
    	}
    	pending.clear();
    }

// int s = 6;
// cout<<"arr: ";for(int i=s;i<=n;i++)	cout<<i<<":"<<arr[i]<<" ";cout<<endl;
// cout<<"cnt[0]: ";for(int i=s;i<=n;i++)	cout<<i<<":"<<cnt[0][i]<<" ";cout<<endl;
// cout<<"cnt[1]: ";for(int i=s;i<=n;i++)	cout<<i<<":"<<cnt[1][i]<<" ";cout<<endl;
// cout<<"DP[0]: ";for(int i=s;i<=n;i++)	cout<<i<<":"<<DP[0][i]<<" ";cout<<endl;
// cout<<"DP[1]: ";for(int i=s;i<=n;i++)	cout<<i<<":"<<DP[1][i]<<" ";cout<<endl;


    printf("%d\n", DP[1]);
    return 0;
}











Measured memory_bytes: 18804