#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




const long long INF = 1LL<<59;
const int MAX_R = 510000;

int SIZE_R;
struct RMQ {
    long long dat[4*MAX_R];
    
    void init(int n = MAX_R, long long v = INF) {
        SIZE_R = 1;
        while (SIZE_R < n) SIZE_R *= 2;
        for (int i = 0; i < 2*MAX_R-1; ++i) dat[i] = v;
    }
    
    inline void init_set(int a, long long x) {
        int k = a + SIZE_R-1;
        dat[k] = x;
    }
    
    inline void init_tree(int k = 0, int l = 0, int r = SIZE_R) {
        if (r - l == 1) {}                  // leaf
        else {
            init_tree(k*2+1, l, (l+r)/2);
            init_tree(k*2+2, (l+r)/2, r);
            dat[k] = min(dat[k*2+1], dat[k*2+2]);
        }
    }
    
    inline void set(int a, long long x) {
        int k = a + SIZE_R-1;
        dat[k] = x;
        while (k > 0) {
            k = (k-1)/2;
            dat[k] = min(dat[k*2+1], dat[k*2+2]);
        }
    }
    
    inline long long get(int a, int b, int k = 0, int l = 0, int r = SIZE_R) {
        if (r <= a || b <= l) return INF;
        if (a <= l && r <= b) return dat[k];
        else {
            long long vl = get(a, b, k*2+1, l, (l+r)/2);
            long long vr = get(a, b, k*2+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }
    
    void print(int r = SIZE_R) {
        for (int i = 0; i < SIZE_R; ++i) {cout << get(i, i+1) << ",";}
        cout << endl;
    }
};

RMQ rmq;




int N, Q;
int b[510000];
int cost[510000];

map<int, vector<int> > ma;

int main() {
    while (cin >> N) {
        int numzero = 0;
        for (int i = 0; i < N; ++i) {
            cin >> b[i];
            if (b[i] == 0) cost[i] = -1, ++numzero;
            else cost[i] = 1;
        }
        cin >> Q;
        ma.clear();
        for (int i = 0; i < Q; ++i) {
            int l, r;
            cin >> l >> r;
            --l;
            ma[l].push_back(r);
        }
        
        rmq.init(N+1);
        rmq.set(0, 0);
        
        for (int i = 0; i < N; ++i) {
            vector<int> right = ma[i];
            for (int j = 0; j < right.size(); ++j) {
                int r = right[j];
                long long val = rmq.get(i, r+1);
                rmq.set(r, min(rmq.get(r, r+1), val));
            }
            rmq.set(i+1, min(rmq.get(i+1, i+2), rmq.get(i, i+1) + cost[i]));
            
            //rmq.print();
        }
        
        cout << rmq.get(N, N+1) + numzero << endl;
    }
}


















Measured memory_bytes: 30848