#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
class Node{
    public:
        long start, end;
        long long increment = 0, sum = 0, minn = 0, maxx = 0;
        Node(){}
        bool intersect(long a, long b){
            return ((b>=start && b<=end) || (a>=start && a<=end) || (a<=start && b>=end));
        }
};
class Tree{
    public:
        vector<Node> p;
        Tree(long n){
            long size = 1;
            while(size<n){
                size*=2L;
            }
            p.resize(2L*(size+1));
            create(0,n,1);
        }
        void create(long s, long e, long i){
            p[i].start = s;
            p[i].end = e;
            long mid = (s+e)/2L;
            if(s!=e){
                create(s,mid,i*2L);
                create(mid+1L,e,i*2L+1L);
            }
        }
        long long sum(long s, long e){
            return getSum(s,e,0, 1);
        }
        long long maximum(long s, long e){
            return getMax(s,e,0, 1);
        }
        long long minimum(long s, long e){
            return getMin(s,e,0, 1);
        }
        void set(long s, long long val){
            //expect-reality
            add(s,s,val-sum(s,s));
        }
        void miniset(long s, long long val){
            add(s,s,min(0LL,val-sum(s,s)));
        }
        void add(long s, long e, long long v){
            addV(s,e,v, 1);
        }
        void addV(long starting, long ending, long long val, long ind){
            long start = p[ind].start;
            long end = p[ind].end;
            long l = ind*2L;
            long r = l+1L;
            if(start>=starting && end<=ending){
                p[ind].increment+=val;
                p[ind].sum+=((long long)end - (long long)start + 1LL)*(long long)val;
                p[ind].minn += (long long) val;
                p[ind].maxx += (long long) val;
            }
            else{
                if(p[l].intersect(starting,ending)){
                    addV(starting,ending, val, l);
                }
                if(p[r].intersect(starting,ending)){
                    addV(starting, ending, val, r);
                }
                p[ind].minn = min(p[l].minn,p[r].minn)+p[ind].increment;
                p[ind].maxx = max(p[l].maxx,p[r].maxx)+p[ind].increment;
                p[ind].sum = p[l].sum+p[r].sum+p[ind].increment*((long long)end- (long long)start + 1LL);
            }
        }
        long long getMin(long starting, long ending, long long added, long ind){
            long start = p[ind].start;
            long end = p[ind].end;
            long l = ind*2L;
            long r = l+1L;
            if(start>=starting && end<=ending){
                return p[ind].minn+added;
            }
            else{
                added+=p[ind].increment;
                long long mini = 9223372036854775807LL;
                if(p[l].intersect(starting, ending)){
                    mini = min(getMin(starting, ending, added, l), mini);
                }
                if(p[r].intersect(starting, ending)){
                    mini= min(getMin(starting,ending,added, r), mini);
                }
                return mini;
            }
        }
        long long getMax(long starting, long ending, long long added, long ind){
            long start = p[ind].start;
            long end = p[ind].end;
            long l = ind*2L;
            long r = l+1L;
            if(start>=starting && end<=ending){
                return p[ind].maxx+added;
            }
            else{
                added+=p[ind].increment;
                long long maxi = -9223372036854775807LL;
                if(p[l].intersect(starting, ending)){
                    maxi = max(getMax(starting, ending, added, l), maxi);
                }
                if(p[r].intersect(starting, ending)){
                    maxi = max(getMax(starting,ending,added, r), maxi);
                }
                return maxi;
            }
        }
        long long getSum(long starting, long ending, long added, long ind){
            long start = p[ind].start;
            long end = p[ind].end;
            long l = ind*2L;
            long r = l+1L;
            if(start>=starting && end<=ending){
                return p[ind].sum+added*((long long)end-(long long)start+1LL);
            }
            else{
                added+=p[ind].increment;
                long long ret = 0;
                if(p[l].intersect(starting, ending)){
                    ret += getSum(starting, ending, added, l);
                }
                if(p[r].intersect(starting,ending)){
                    ret += getSum(starting, ending, added, r);
                }
                return ret;
            }
        }
};
class Query{
    public:
        int l, r;
        Query(int a, int b){
            l = a;
            r = b;
        }
        bool operator<(const Query &o) const{
            return l<o.l;
        }
};
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    bool on[n];
    for(int i = 0; i<n; i++){
        int x;
        cin >> x;
        on[i] = x==1;
    }
    Tree tree = Tree(n+5);
    tree.add(0,n,2000000);
    tree.set(0,0);
    int q;
    cin >> q;
    vector<Query> li;
    for(int i = 0; i<q; i++){
        int a, b;
        cin >> a >> b;
        li.push_back(Query(a,b));
    }
    sort(li.begin(),li.end());
    int p = 0;
    tree.set(0,0);
    for(int i = 1; i<=n; i++){
        while(p<li.size() && li[p].l==i){
            long long maxi = tree.minimum(0,li[p].r-1);
            tree.miniset(li[p].r,maxi);
            p++;
        }
        if(on[i-1]){
            tree.add(0,i-1,1LL);
        }
        else{
            tree.add(i,n,1LL);
        }
    }
    cout << tree.minimum(0,n) << endl;
    return 0;
}

Measured memory_bytes: 27252