#define LOCAL

#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

// From Errichto's Youtube stream
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
const int MAXN = (1<<18);
const int INF = (1<<21);

int N, Q;
int B[MAXN], pref[MAXN], op[MAXN];
vector<vector<int>> cand;

int dp[MAXN];

struct SegTree {
    int tree[2*MAXN];
    int lazy[2*MAXN];

    SegTree() {
        for (int i = 0; i < 2 * MAXN; i++) {
            tree[i] = INF;
            lazy[i] = INF;
        }
    }

    void Push (int n, int nl, int nr) {
        if (lazy[n] != INF) {
            if (nl != nr) {
                lazy[2*n] = min(lazy[2*n], lazy[n]);
                tree[2*n] = min(tree[2*n], lazy[n]);

                lazy[2*n+1] = min(lazy[2*n+1], lazy[n]);
                tree[2*n+1] = min(tree[2*n+1], lazy[n]);
            }
            
            lazy[n] = INF;
        }
    }

    void Update(int n, int nl, int nr, int l, int r, int val) {
        if (l <= nl && nr <= r) {
            lazy[n] = min(lazy[n], val);
            tree[n] = min(tree[n], val);
        } else {
            Push(n, nl, nr);

            int m = (nl + nr) >> 1;

            if (l <= m) {
                Update(2 * n, nl, m, l, r, val);
            }

            if (r >= m + 1) {
                Update(2 * n + 1, m + 1, nr, l, r, val);
            }

            tree[n] = min(tree[2*n], tree[2*n+1]);
        }
    }

    int Query(int n, int nl, int nr, int l, int r) {
        if (l <= nl && nr <= r) {
            //debug() << "Q : " << n << " " << nl << " " << nr << " " << lazy[n] << " " << tree[n];
            return tree[n];
        } else {
            Push(n, nl, nr);

            int m = (nl + nr) >> 1;
            int result = INF;

            if (l <= m) {
                result = min(result, Query(2 * n, nl, m, l, r));
            }

            if (r >= m + 1) {
                result = min(result, Query(2 * n + 1, m + 1, nr, l, r));
            }

            return result;
        }
    }
};

void Test() {
    N = 5;
    SegTree s;

    s.Update(1, 0, MAXN - 1, 1, 3, 4);
    debug() << s.Query(1, 0, MAXN - 1, 1, 3);
    s.Update(1, 0, MAXN - 1, 2, 3, 3);
    debug() << s.Query(1, 0, MAXN - 1, 1, 3);

    s.Update(1, 0, MAXN - 1, 3, 4, 2);
    debug() << s.Query(1, 0, MAXN - 1, 1, 3);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    //Test(); return 0;

    cin >> N;
    for (int i = 1; i <= N; i++) {
        cin >> B[i];

        pref[i] = pref[i-1] + B[i];
        op[i] = i - pref[i];
    }

    cand.resize(N + 1);

    cin >> Q;
    for (int i = 1; i <= Q; i++) {
        int l, r;
        cin >> l >> r;

        cand[r].push_back(l);
    }

    for (int i = 1; i <= N; i++) {
        sort(cand[i].begin(), cand[i].end());
    }

    dp[0] = 0;
    for (int i = 1; i <= N; i++)
        dp[i] = INF;

    SegTree segtree;

    vector<int> A(N + 1, INF);

    for (int i = 1; i <= N; i++) {
        // default.
        dp[i] = dp[i-1] + (B[i] != 0);

        //debug() << "i " << dp[i];

        for (auto j : cand[i]) {
            //debug() << " -> " << j << " " << dp[j-1];
            dp[i] = min(dp[i], dp[j-1] + op[i] - op[j-1]);
            
            auto bst = segtree.Query(1, 0, MAXN - 1, j, j);
            
            // int bst = INF;
            // for (int k = j; k <= j; k++)
            //     bst = min (bst, A[k]);

            dp[i] = min(dp[i], op[i] + bst);

            // for (int k = j; k <= i; k++) {
            //     A[k] = min (A[k], bst);
            //     A[k] = min (A[k], dp[j-1] + op[i] - op[j-1]);
            // }
            segtree.Update(1, 0, MAXN - 1, j, i, bst);
            segtree.Update(1, 0, MAXN - 1, j, i, dp[j-1] - op[j-1]);
        }

        //debug() << i << " " << dp[i] << " " << op[i];
    }

    cout << dp[N] << "\n";

    return 0;
}


Measured memory_bytes: 18304