#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
#include<cassert>
#include<random>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
#define INF 1000000000LL
#define EPS 1e-12
#define FOR(i,n,m) for(int i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

#include <cstdint>
using i64 = std::int_fast64_t;
const static i64 mod = 1000000007;
struct mint {
	i64 n;
public:
	mint(const i64 n = 0) : n((n % mod + mod) % mod) {}
	mint pow(int m) const {
		i64 a = n, r = 1;
		while(m > 0) {
			if(m & 1) { r *= a; r %= mod; }
			a = (a * a) % mod; m /= 2;
		}
		return mint(r);
	}
	mint &operator++() { *this += 1; return *this; }
	mint &operator--() { *this -= 1; return *this; }
	mint operator++(int) { mint ret = *this; *this += 1; return ret; }
	mint operator--(int) { mint ret = *this; *this -= 1; return ret; }
	mint operator~() const { return (this -> pow(mod - 2)); } // inverse
	friend bool operator==(const mint& lhs, const mint& rhs) {
		return lhs.n == rhs.n;
	}
	friend bool operator<(const mint& lhs, const mint& rhs) {
		return lhs.n < rhs.n;
	}
	friend bool operator>(const mint& lhs, const mint& rhs) {
		return lhs.n > rhs.n;
	}
	friend mint &operator+=(mint& lhs, const mint& rhs) {
		lhs.n += rhs.n;
		if (lhs.n >= mod) lhs.n -= mod;
		return lhs;
	}
	friend mint &operator-=(mint& lhs, const mint& rhs) {
		lhs.n -= rhs.n;
		if (lhs.n < 0) lhs.n += mod;
		return lhs;
	}
	friend mint &operator*=(mint& lhs, const mint& rhs) {
		lhs.n = (lhs.n * rhs.n) % mod;
		return lhs;
	}
	friend mint &operator/=(mint& lhs, const mint& rhs) {
		lhs.n = (lhs.n * (~rhs).n) % mod;
		return lhs;
	}
	friend mint operator+(const mint& lhs, const mint& rhs) {
		return mint(lhs.n + rhs.n);
	}
	friend mint operator-(const mint& lhs, const mint& rhs) {
		return mint(lhs.n - rhs.n);
	}
	friend mint operator*(const mint& lhs, const mint& rhs) {
		return mint(lhs.n * rhs.n);
	}
	friend mint operator/(const mint& lhs, const mint& rhs) {
		return mint(lhs.n * (~rhs).n);
	}
};
istream& operator>>(istream& is, mint& m) { is >> m.n; return is; }
ostream& operator<<(ostream& os, mint& m) { os << m.n; return os; }

mint _pow(mint a, long long n) {
	if(n == 0) return 1;
	mint res = 1;
	mint buf = a;
	while(n > 0) {
		if(n % 2) res *= buf;
		buf *= buf;
		n /= 2;
	}
	return res;
}

/////// Starry Sky Tree ///////
static const int MAX_SIZE = 1 << 18;
ll segMax[2 * MAX_SIZE - 1], segAdd[2 * MAX_SIZE - 1];
void add(int a, int b, ll x, int k = 0, int l = 0, int r = MAX_SIZE) {
	if (r <= a || b <= l) return;
	if (a <= l && r <= b) {
		segAdd[k] += x;
		return;
	}
	add(a, b, x, k * 2 + 1, l, (l + r) / 2);
	add(a, b, x, k * 2 + 2, (l + r) / 2, r);
	segMax[k] = max(segMax[k * 2 + 1] + segAdd[k * 2 + 1], segMax[k * 2 + 2] + segAdd[k * 2 + 2]);
}

ll getMax(int a, int b, int k = 0, int l = 0, int r = MAX_SIZE) {
	if (r <= a || b <= l) return -INF;
	if (a <= l && r <= b) return (segMax[k] + segAdd[k]);
	ll left = getMax(a, b, k * 2 + 1, l, (l + r) / 2);
	ll right = getMax(a, b, k * 2 + 2, (l + r) / 2, r);
	return (max(left, right) + segAdd[k]);
}
/////// Starry Sky Tree ///////

int main() {
	using mi = mint;
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n;
	vector<int> b(n);
	REP(i, n) cin >> b[i];
	cin >> q;
	priority_queue<P, vector<P>, greater<P>> q1;
	REP(i, q) {
		ll l, r;
		cin >> l >> r;
		q1.push({--l, --r});
	}
	add(0, MAX_SIZE, -INF);
	ll sum = 0;
	REP(i, n) {
		while(!q1.empty() && q1.top().first == i) {
			auto opt = q1.top();
			q1.pop();
			ll mx = max(0LL, getMax(0, opt.second));
			if(mx > getMax(opt.second, opt.second + 1)) {
				add(opt.second, opt.second + 1, mx - getMax(opt.second, opt.second + 1));
			}
		}
		if(b[i]) add(i, n, 1);
		else add(i, n, -1);
		if(b[i]) sum++;
	}
	cout << min(sum, sum - getMax(0, n)) << endl;
	return 0;
}

// ---------------------------------------


Measured memory_bytes: 10860