#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
#define fo(a,b) for(int o=a;o<b;++o)
#define fdi(a,b) for(int i=a-1;i>=b;--i)
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
//////////////////////

#ifdef _DEBUG
int const N = 41;
#else
int const N = 2e5 + 41;
#endif

int const INF = 1e9 + 41;

int n, qu, l[N], r[N], bs[N];
vector<int> qid[N];
int d[N], b[N];
int ans;

void remin(int &a, int b){
	a = min(a, b);
}

int getsuf(int l, int r){
	if(l > r) return 0;
	return bs[l] - bs[r+1];
}

namespace tree{
#ifdef _DEBUG
	int const B = (1 << 8);
#else
	int const B = (1 << 19);
#endif

	vector<int> F[B], t[B];
	int l, r, val, ll;
	int n;
	vector<pii> qr;
	vector<pii> pt[N];

	void updfen(vector<int> &F, int x, int v){
		while(x < sz(F)){
			remin(F[x], v);
			x |= (x + 1);
		}
	}

	int getfen(vector<int> &F, int x){
		int res = INF;
		while(x >= 0){
			remin(res, F[x]);
			x = (x&(x+1)) - 1;
		}
		return res;
	}
	
	void merge(int v, int l, int r){
		int lp = 0;
		int rp = 0;
		int ln = sz(t[l]);
		int rn = sz(t[r]);
		while(lp < ln || rp < rn){
			if(rp == rn || (lp < ln && ::l[t[l][lp]] < ::l[t[r][rp]])){
				t[v].pb(t[l][lp]);
				++lp;
			}else{
				t[v].pb(t[r][rp]);
				++rp;
			}
		}
	}

	void build(int v, int tl, int tr){
		if(tl == tr){
			t[v].pb(qr[tl].second);
		}else{
			int tm = (tl+tr)/2;
			build(v*2+1, tl, tm);
			build(v*2+2, tm+1, tr);
			merge(v, v*2+1, v*2+2);
		}
		fi(0, sz(t[v])) F[v].pb(INF);
		fi(0, sz(t[v])){
			pt[t[v][i]].pb(mp(v, i));
		}
	}

	void init(){
		n = qu;
		fi(0, qu) qr.pb(mp(::r[i], i));
		sort(qr.begin(), qr.end());
		build(0, 0, n-1);
	}

	void ins(int id, int val){
		fi(0, sz(pt[id])){
			updfen(F[pt[id][i].first], pt[id][i].second, val);
		}
	}

	int getless(vector<int> &vid, int ll){
		int l = -1;
		int r = sz(vid);
		while(r-l>1){
			int m = (l+r)/2;
			if(::l[vid[m]] < ll) l = m;
			else r = m;
		}
		return l;
	}

	int ask(int v, int tl, int tr){
		if(l > tr || tl > r) return INF;
		if(l <= tl && tr <= r){
			int p = getless(t[v], ll);
			return getfen(F[v], p);
		}
		int tm = (tl+tr)/2;
		return min(ask(v*2+1, tl, tm), ask(v*2+2, tm+1, tr));
	}

	int getl(int lr){
		int l = -1;
		int r = sz(qr);
		while(r-l>1){
			int m = (l+r)/2;
			if(qr[m].first >= lr) r = m;
			else l = m;
		}
		return r;
	}

	int getr(int rr){
		int l = -1;
		int r = sz(qr);
		while(r-l>1){
			int m = (l+r)/2;
			if(qr[m].first < rr) l = m;
			else r = m;
		}
		return l;
	}

	int ask(int lr, int rr){
		tree::l = getl(lr);
		tree::r = getr(rr);
		tree::ll = lr;
		return ask(0, 0, n-1);
	}
};

void solve(){
	fdi(n+1, 1) bs[i] = bs[i+1] + b[i];
	tree::init();
	fi(1, n+1) d[i] = INF;
	fi(0, qu) qid[r[i]].pb(i);
	fi(1, n+1){
		//1
		remin(d[i], d[i-1] + b[i]);
		//2
		fj(0, sz(qid[i])){
			int id = qid[i][j];
			int len = r[id] - l[id] + 1;
			remin(d[i], d[i-len] + len - getsuf(l[id], r[id]));
		}
		//3
		fj(0, sz(qid[i])){
			int id = qid[i][j];
			int val = tree::ask(l[id], r[id]);
			int c = n - i - getsuf(i+1, n);
			remin(d[i], val - c);
		}
		fj(0, sz(qid[i])){
			int id = qid[i][j];
			int val = tree::ask(l[id], r[id]);
			int len = r[id] - l[id] + 1;
			remin(val, d[i-len] + (n - l[id] + 1) - getsuf(l[id], n));
			tree::ins(id, val);
		}
	}
	ans = d[n];
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);
	fi(1, n+1) scanf("%d",&b[i]);
	scanf("%d",&qu);
	fi(0, qu)	scanf("%d %d",&l[i],&r[i]);

	solve();

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 152688