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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MINF = 0x3f3f3f3f;
const int MAXN = 200007;
const int MAXS = MAXN * 4;
const int MAX = 262144;
/*
class ftT
{
public:
	void upd ( int p, int x )
	{
		for ( ; p < MAXN; p += p&-p ) data[p] = qmax ( data[p], x );
	}

	int query ( int p )
	{
		int ans = 0;
		for ( ; p; p ^= p&-p ) ans = qmax ( ans, data[p] );
		return ans;
	}

private:
	int data[MAXN];
}ft;*/

class stT
{
public:
	stT ()
	{
		fill ( tag, tag+MAXS, -INF );
		fill ( data, data+MAXS, -INF );
	}

	void upd ( int l, int r, int x, int now = 1, int ll = 1, int rr = MAX )
	{
		if ( ll >= l && rr <= r ) tag[now] = qmax ( tag[now], x ), data[now] = qmax ( data[now], x );
		else if ( ll > r || rr < l ) return;
		else {
			int mid = ( ll + rr ) >> 1;
			downtag ( now );
			upd ( l, r, x, now<<1, ll, mid );
			upd ( l, r, x, now<<1|1, mid+1, rr );
			data[now] = qmax ( data[now<<1], data[now<<1|1] );
		}
	}

/*	int query ( int l, int r, int now = 1, int ll = 1, int rr = MAX )
	{
		if ( ll >= l && rr <= r ) return data[now];
		else if ( ll > r || rr < l ) return -INF;
		else {
			int mid = ( ll + rr ) >> 1;
			downtag ( now );
			return max ( query ( l, r, now<<1, ll, mid ), query ( l, r, now<<1|1, mid+1, rr ) );
		}
	}*/

	int query ( int p, int now = 1, int ll = 1, int rr = MAX )
	{
		if ( p >= ll && p <= rr ) {
			if ( ll == rr ) return data[now];

			int mid = ( ll + rr ) >> 1;
			downtag ( now );
			return ( max ( query ( p, now<<1, ll, mid ), query ( p, now<<1|1, mid+1, rr ) ) );
		} else return -INF;
	}

private:
	void downtag ( int now )
	{
		if ( tag[now] ^ -INF ) {
			data[now<<1] = qmax ( data[now<<1], tag[now] );
			data[now<<1|1] = qmax ( data[now<<1|1], tag[now] );
			tag[now<<1] = qmax ( tag[now<<1], tag[now] );
			tag[now<<1|1] = qmax ( tag[now<<1|1], tag[now] );
			tag[now] = -INF;
		}
	}

	int tag[MAXS], data[MAXS];
}st;

struct qT
{
	int id, l, r;
}que[MAXN];

int n;
int a[MAXN];
int ps[MAXN], sc[MAXN];
int q;
int dp[MAXN];

AR ( int ) il[MAXN], ir[MAXN];

void init ();
void input ();
void work ();



int main ()
{
	init ();
	input ();
	work ();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d", &n );
	lpi ( i, 1, n ) scanf ( "%d", &a[i] );
	scanf ( "%d", &q );
	lpi ( i, 1, q ) scanf ( "%d%d", &que[i].l, &que[i].r );
}

void work ()
{
	// main work

	lpi ( i, 1, n ) ps[i] = ps[i-1] + ( a[i] ? 0 : 1 ), sc[i] = sc[i-1] + ( a[i] ? 1 : -1 );

	lpi ( i, 1, q ) que[i].id = i, il[que[i].l].push_back ( i ), ir[que[i].r].push_back ( i ), dp[i] = sc[que[i].r] - sc[que[i].l-1];

	int sl, sr, cmax = -INF;
	lpi ( i, 1, n ) {
		sr = ir[i].size ();
		lp ( j, 0, sr ) {
			dp[que[ir[i][j]].id] = max ( dp[que[ir[i][j]].id], st.query ( que[ir[i][j]].l ) + sc[que[ir[i][j]].r] );
		}
		lp ( j, 0, sr )
			st.upd ( que[ir[i][j]].l+1, que[ir[i][j]].r, dp[que[ir[i][j]].id] - sc[que[ir[i][j]].r] );
		sl = il[i].size ();
		lp ( j, 0, sl ) dp[que[il[i][j]].id] = qmax ( dp[que[il[i][j]].id], cmax + sc[que[il[i][j]].r] - sc[que[il[i][j]].l-1] );
		lp ( j, 0, sr ) cmax = qmax ( cmax, dp[que[ir[i][j]].id] );
	}

	int ans = 0;
	lpi ( i, 1, q ) ans = qmax ( ans, dp[i] );

	cout << ( n - ( ps[n] + ans ) ) << endl;
}

Measured memory_bytes: 29312