#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() {cout << "\n";}
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

template<typename T, typename U, typename F, typename G, typename H>
struct LazySegmentTree {
    F f;
    G g;
    H h;
    T unitynode;
    U unitylazy;
    int N,height;
    vector<T> node;
    vector<U> lazy;

    LazySegmentTree() {}
    LazySegmentTree(F f, G g, H h, T unitynode, U unitylazy) : f(f), g(g), h(h), unitynode(unitynode), unitylazy(unitylazy) {}

    void init(int sz) {
        N = 1;
        height = 0;
        while (N < sz) {
            N <<= 1;
            ++height;
        }
        node.assign(2*N,unitynode);
        lazy.assign(2*N,unitylazy);
    }

    void set(int k, const T &val) {node[k+N] = val;}

    void build() {
        for (int i = N-1; i > 0; --i) {
            node[i] = f(node[i<<1|0],node[i<<1|1]);
        }
    }

    inline T reflect(int k) {
        return lazy[k] == unitylazy ? node[k] : g(node[k],lazy[k]);
    }

    void eval(int k) {
        if (lazy[k] == unitylazy) return;
        if (k < N) {
            lazy[k<<1|0] = h(lazy[k<<1|0],lazy[k]);
            lazy[k<<1|1] = h(lazy[k<<1|1],lazy[k]);
        }
        node[k] = reflect(k);
        lazy[k] = unitylazy;
    }

    inline void recalc(int k) {
        while (k >>= 1) {
            node[k] = f(reflect(k<<1|0),reflect(k<<1|1));
        }
    }

    // [l,r) (0-indexed)
    void update(int l, int r, U val) {
        if (l >= r) return;
        l += N; r += N-1;
        for (int i = height; i > 0; --i) {
            eval(l>>i);
            eval(r>>i);
        }
        int a = l; int b = r++;
        while (l < r) {
            if (l & 1) lazy[l] = h(lazy[l],val), ++l;
            if (r & 1) --r, lazy[r] = h(lazy[r],val);
            l >>= 1; r >>= 1;
        }
        recalc(a);
        recalc(b);
    }

    T get(int l, int r) {
        if (l >= r) return unitynode;
        l += N; r += N-1;
        for (int i = height; i > 0; --i) {
            eval(l>>i);
            eval(r>>i);
        }
        ++r;
        T vl = unitynode, vr = unitynode;
        while (l < r) {
            if (l & 1) vl = f(vl,reflect(l++));
            if (r & 1) vr = f(reflect(--r),vr);
            l >>= 1; r >>= 1;
        }
        return f(vl,vr);
    }

    template<typename C>
    int binarysearch(int s, C &check, T &acc, int k, int l, int r) {
        if(r-l==1) {
            acc = f(acc,reflect(k));
            return check(acc) ? k-N : -1;
        }
        eval(k);
        int m = (l+r)>>1;
        if(m <= s) return binarysearch(s, check, acc, (k<<1)|1, m, r);
        if(s <= l && !check(f(acc,node[k]))){
            acc = f(acc,node[k]);
            return -1;
        }
        int vl = binarysearch(s, check, acc, (k<<1)|0, l, m);
        if(~vl) return vl;
        return binarysearch(s, check, acc, (k<<1)|1, m, r);
    }

    template<typename C>
    int binarysearch(int s ,C &check) {
        T acc = unitynode;
        return binarysearch(s,check,acc,1,0,N);
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> B(N);
    rep(i,N) cin >> B[i];
    int Q; cin >> Q;
    vector<int> L(Q),R(Q);
    rep(i,Q) cin >> L[i] >> R[i], --L[i];

    vector<int> idx_l(Q),idx_r(Q),idxinv_r(Q);
    iota(all(idx_l),0);
    iota(all(idx_r),0);
    sort(all(idx_l),[&](int i, int j){return L[i] < L[j];});
    sort(all(idx_r),[&](int i, int j){return R[i] < R[j];});
    rep(i,Q) idxinv_r[idx_r[i]] = i;

    auto f=[](int a, int b) {return min(a,b);};
    auto g=[](int a, pii val) {
        if (val.second) {
            //区間加算
            a += val.first;
        } else {
            //区間更新
            a = val.first;
        }
        return a;
    };
    auto h=[](pii a, pii b) {
        if (b.second) {
            a.first += b.first; 
        } else {
            a.second = 0;
            a.first = b.first;
        }
        return a;
    };
    const int id1 = 1e9;
    const pii id2 = pii(0,1);
    LazySegmentTree seg(f,g,h,id1,id2);
    seg.init(Q);
    seg.build();

    vector<int> dp(N+1,1e9);
    dp[0] = 0;
    int cur_l = 0, cur_r = 0;
    rep(i,N) {
        if (B[i]) chmin(dp[i+1],dp[i]+1);
        else chmin(dp[i+1],dp[i]);
        while (cur_l < Q and L[idx_l[cur_l]] == i) {
            int u = idx_l[cur_l];
            int r_idx = idxinv_r[u];
            int val = dp[i];
            chmin(val,seg.get(0,r_idx));
            seg.update(r_idx,r_idx+1,pii(val,0));
            cur_l++;
        }
        while (cur_r < Q and R[idx_r[cur_r]] == i) {
            if (B[i]) chmin(dp[i+1],seg.get(cur_r,cur_r+1)+1);
            else chmin(dp[i+1],seg.get(cur_r,cur_r+1));
            seg.update(cur_r,cur_r+1,pii(id1,0));
            cur_r++;
        }
        if (!B[i]) seg.update(0,Q,pii(1,1));
    }

    cout << min(dp[N],seg.get(0,Q)) << ln;
}


Measured memory_bytes: 14840