/*
PROG: arc085f
LANG: C++
    _____
  .'     '.
 /  0   0  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
 */
#include <bits/stdc++.h>

using namespace std;

long long readi()
{
	long long input = 0;
	char c = ' ';
	while (c < '-')
	{
		c = getchar();
	}
	bool negative = false;
	if (c == '-')
	{
		negative = true;
		c = getchar();
	}
	while (c >= '0')
	{
		input = 10 * input + (c - '0');
		c = getchar();
	}
	if (negative)
	{
		input = -input;
	}
	return input;
}
void printi(long long output)
{
	if (output == 0)
	{
		putchar('0');
		return;
	}
	if (output < 0)
	{
		putchar('-');
		output = -output;
	}
	int aout[20];
	int ilen = 0;
	while(output)
	{
		aout[ilen] = ((output % 10));
		output /= 10;
		ilen++;
	}
	for (int i = ilen - 1; i >= 0; i--)
	{
		putchar(aout[i] + '0');
	}
	return;
}
string reads()
{
	string input = "";
	char c = ' ';
	while (c <= ' ')
	{
		c = getchar();
	}
	while (c > ' ')
	{
		input += c;
		c = getchar();
	}
	return input;
}
void prints(string output)
{
	for (int i = 0; i < output.length(); i++)
	{		
		putchar(output[i]);
	}
	return;
}
int sgn(long long x)
{
	if (x < 0) 
	{
		return -1;
	}
	if (x > 0) 
	{
		return 1;
	}
	return 0;
}

#define MP make_pair
#define PB push_back
#define PF push_front
#define MT make_tuple
#define LB lower_bound
#define UB upper_bound

#define SINF 10007
#define MOD 1000000007
#define INF 1000000861
#define LLINF 1000000000000000861int
#define CO 1000861
#define EPS 0.000000000000001
#define PI 3.141592653589793
#define MAXN 200010

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, int> pll;

int N, Q;
int arr[MAXN];
int pref[MAXN];
vector<int> query[MAXN];
int dp[MAXN];
int ans;

struct segtree
{
	int minst[4 * MAXN];
	int query(int w, int L, int R, int a, int b)
	{
		if (b < L || R < a)
		{
			return INF;
		}
		if (a <= L && R <= b)
		{
			return minst[w];
		}
		int mid = (L + R)/2;
		return min(query(2 * w, L, mid, a, b), query(2 * w + 1, mid + 1, R, a, b));
	}
	void update(int w, int L, int R, int a, int val)
	{
		if (a < L || R < a)
		{
			return;
		}
		if (L == R)
		{
			minst[w] = val;
			return;
		}
		int mid = (L + R)/2;
		update(2 * w, L, mid, a, val);
		update(2 * w + 1, mid + 1, R, a, val);
		minst[w] = min(minst[2 * w], minst[2 * w + 1]);
		return;
	}
};

segtree seg;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	srand(time(NULL));
	//	cout << fixed << setprecision(10);	
	//	cerr << fixed << setprecision(10);
	//	if (fopen("arc085f.in", "r"))
	//	{	
	//		freopen ("arc085f.in", "r", stdin);
	//		freopen ("arc085f.out", "w", stdout);
	//	}
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> arr[i];
		if (arr[i] == 0)
		{
			arr[i] = -1;
		}
	}
	cin >> Q;
	while(Q--)
	{
		int lt, rt;
		cin >> lt >> rt;
		query[lt].PB(rt);
	}
	for (int i = 1; i <= N; i++)
	{
		seg.update(1, 0, N, i, INF);
	}
	for (int i = 1; i <= N; i++)
	{
		sort(query[i].begin(), query[i].end());
		reverse(query[i].begin(), query[i].end());
		for (int rt : query[i])
		{
			seg.update(1, 0, N, rt, seg.query(1, 0, N, i - 1, rt));
		}
		int lt = seg.query(1, 0, N, i - 1, i - 1) + arr[i];
//		cerr << lt << endl;
		if (lt < seg.query(1, 0, N, i, i))
		{
			seg.update(1, 0, N, i, lt);
		}
	}
	ans = seg.query(1, 0, N, N, N);
	for (int i = 1; i <= N; i++)
	{
		if (arr[i] == -1)
		{
			ans++;
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 13696