#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 1e17;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
// #define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,ans,a,c,d,e,h,r,l,q;
ll k;
ll b[500005];
ll x[500005], y[500005], z[500005];
char s[500005], t[500005];
P table[500005];
ll dp[500005];

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;
    vector<bool> lazyFlag;
 
public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, INF);
        lazyFlag.resize(2*n-1, false);
 
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
 
    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = min(lazy[k], node[k]);
            if(r - l > 1) {
                lazy[k*2+1] = min(lazy[k*2+1], lazy[k]);
                lazy[k*2+2] = min(lazy[k*2+2], lazy[k]);
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }
 
    void update(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        //update node[a, b) to x
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }
 
    ll find(int a, int b, int k=0, int l=0, int r=-1) {
        //find minimum of node[a, b)
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return INF;
        if(a <= l && r <= b) return node[k];
        ll vl = find(a, b, 2*k+1, l, (l+r)/2);
        ll vr = find(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

LazySegmentTree seg0(vector<ll> (200010, INF));
LazySegmentTree seg1(vector<ll> (200010, INF));
LazySegmentTree seg0valid(vector<ll> (200010, 0));
LazySegmentTree seg1valid(vector<ll> (200010, -1));

ll countone(ll l, ll r){
    // 1-indexでの[l, r]の中にある1の個数を返す
    l--;r--;
    if(l == 0){
        return b[r];
    }else{
        return b[r] - b[l-1];
    }
}

ll countzero(ll l, ll r){
    return r - l + 1 - countone(l, r);
}

int main(){
    cin >> n;
    for(ll i=0;i<n;i++){
        cin >> b[i];
    }
    for(ll i=0;i<n;i++){
        b[i+1] += b[i];
    }
    cin >> q;
    for(ll i=0;i<q;i++){
        cin >> x[i] >> y[i];
        table[i].first = y[i];
        table[i].second = x[i];
    }
    sort(table, table + q);
    for(ll i=0;i<q;i++){
        x[i] = table[i].second;
        y[i] = table[i].first;
    }
    for(ll i=1;i<=n;i++){
        dp[i] = countone(1, i);
        seg1.update(i, i + 1, countone(1, i));
    }
    dp[0] = 0;
    for(ll i=1;i<=q;i++){
        // i個目の区間について考える
        ll l, r;
        l = x[i-1]; r = y[i-1];

        if(seg0valid.find(l-1, l) < 0){
            dp[l-1] = min(dp[l-1], seg0.find(l-1, l) + countzero(1, l-1));
        }
        if(seg1valid.find(l-1, l) < 0){
            dp[l-1] = min(dp[l-1], seg1.find(l-1, l) + countone(1, l-1));
        }

        ll value1 = dp[l-1] - countzero(1, l-1);
        seg0.update(l, r+1, value1);
        seg0valid.update(l, r+1, -1);

        if(seg0valid.find(r, r+1) < 0){
            dp[r] = min(dp[r], seg0.find(r, r+1) + countzero(1, r));
        }
        if(seg1valid.find(r, r+1) < 0){
            dp[r] = min(dp[r], seg1.find(r, r+1) + countone(1, r));
        }
        ll value2 = dp[r] - countone(1, r);
        
        seg1.update(r+1, n+1, value2);
        seg1valid.update(r+1, n+1, -1);
        
        /*
        p("-----");
        for(ll j=1;j<=n;j++){
            pe(seg0valid.find(j, j+1));
        }
        el;
        for(ll j=1;j<=n;j++){
            pe(seg1valid.find(j, j+1));
        }
        el;
        for(ll j=1;j<=n;j++){
            pe(seg0.find(j, j+1));
        }
        el;
        for(ll j=1;j<=n;j++){
            pe(seg1.find(j, j+1));
        }
        el;
        */

    }
    ll ans = countone(1, n);
    if(seg0valid.find(n, n+1) < 0){
        ans = min(ans, seg0.find(n, n+1) + countzero(1, n));
    }
    if(seg1valid.find(n, n+1) < 0){
        ans = min(ans, seg1.find(n, n+1) + countone(1, n));
    }
    p(ans);
    return 0;
}


















Measured memory_bytes: 50788