#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 1<<18;

struct node{
	int add, val;
}t[MX*2];

void pushdown(int n){
	if( t[n].add ){
		t[n*2].add += t[n].add;
		t[n*2].val += t[n].add;
		t[n*2+1].add += t[n].add;
		t[n*2+1].val += t[n].add;
		t[n].add = 0;
	}
}

int mx_range(int l, int r, int n = 1, int s = 0, int e = MX-1)
{
	if( l <= s && e <= r ) return t[n].val;
	else if( r < s || e < l ) return -1e9;
	else{
		pushdown(n);
		int m = (s+e) / 2;
		return max(mx_range(l, r, n*2, s, m), mx_range(l, r, n*2+1, m+1, e));
	}
}

void add_range(int l, int r, int v, int n = 1, int s = 0, int e = MX-1)
{
	if( l <= s && e <= r ) t[n].val += v, t[n].add += v;
	else if( r < s || e < l ) return;
	else{
		pushdown(n);
		int m = (s+e) / 2;
		add_range(l, r, v, n*2, s, m);
		add_range(l, r, v, n*2+1, m+1, e);
		t[n].val = max(t[n*2].val, t[n*2+1].val);
	}
}

int read_point(int x){ return mx_range(x, x); }
void update_point(int x, int v, int n = 1, int s = 0, int e = MX-1)
{
	if( s == e ) t[n].val = v;
	else{
		pushdown(n);
		int m = (s+e) / 2;
		if( x <= m ) update_point(x, v, n*2, s, m);
		else update_point(x, v, n*2+1, m+1, e);
		t[n].val = max(t[n*2].val, t[n*2+1].val);
	}
}

int O[MX], Z[MX], D[MX];
int N, Q;

void sweeping(int b, int n){
	add_range(n, N+1, Z[n-1] - Z[b-1]);
	int mx = read_point(n);
	for(int i = b; i <= n-1; i++){
		int v = read_point(i) + (O[n-1] - O[i-1]) + (Z[i-1] - Z[b-1]);
		mx = max(mx, v);
	}
	update_point(n, mx);
}

void update_query(int l, int r){
	int v = mx_range(l, r+1);
	update_point(r+1, v);
}

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		scanf("%d", D+i);
		if(D[i]) Z[i] = 1;
		else O[i] = 1;
	}
	for(int i = 1; i <= N; i++) Z[i] += Z[i-1];
	for(int i = 1; i <= N; i++) O[i] += O[i-1];
	vector<pii> L;
	scanf("%d", &Q);
	for(int i = 1; i <= Q; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		L.emplace_back(a, b);
	}
	sort(L.begin(), L.end());
	int p = 1;
	for(int i = 2; i <= N+1; i++) update_point(i, -1e9);
	for(pii c : L){
//		printf("%d - %d\n", c.first, c.second);
//		for(int i = 1; i <= N+1; i++) printf("%d ", read_point(i)); printf("\n");
		sweeping(p, c.first); p = c.first;
//		for(int i = 1; i <= N+1; i++) printf("%d ", read_point(i)); printf("\n");
		update_query(c.first, c.second);
//		for(int i = 1; i <= N+1; i++) printf("%d ", read_point(i)); printf("\n");
	}
	sweeping(p, N+1);
//	for(int i = 1; i <= N+1; i++) printf("%d ", read_point(i)); printf("\n");
	printf("%d\n", N - read_point(N+1));
}


Measured memory_bytes: 8176