#include <iostream>
#include <vector>
#define MAXN 200005
#define INF 0x3f3f3f3f
using namespace std;

struct AiNode {
    int val, lazy;

    AiNode(): val(0), lazy(0) {}
};

int n, b[MAXN], nq, aiInit[MAXN];
vector<int> qs[MAXN];
AiNode ai[4 * MAXN];

void buildAi(int node, int left, int right) {
    if (left == right) {
        ai[node].val = aiInit[left];
        return;
    }

    int mid = (left + right) / 2;
    buildAi(2 * node, left, mid);
    buildAi(2 * node + 1, mid + 1, right);
    ai[node].val = min(ai[2 * node].val, ai[2 * node + 1].val);
}

inline void lazyUpdate(int node) {
    int x = ai[node].lazy;
    if (x > 0) {
        ai[node].lazy = 0;
        ai[2 * node].val += x;
        ai[2 * node + 1].val += x;
        ai[2 * node].lazy += x;
        ai[2 * node + 1].lazy += x;
    }
}

void queryAi(int node, int left, int right, int lq, int rq, int &ans) {
    if (lq <= left && right <= rq) {
        ans = min(ans, ai[node].val);
        return;
    }

    lazyUpdate(node);
    int mid = (left + right) / 2;

    if (lq <= mid)
        queryAi(2 * node, left, mid, lq, rq, ans);
    if (mid + 1 <= rq)
        queryAi(2 * node + 1, mid + 1, right, lq, rq, ans);
}

void updateRangeAi(int node, int left, int right, int lq, int rq, int val) {
    if (lq <= left && right <= rq) {
        ai[node].val += val;
        ai[node].lazy += val;
        return;
    }

    lazyUpdate(node);
    int mid = (left + right) / 2;
    if (lq <= mid)
        updateRangeAi(2 * node, left, mid, lq, rq, val);
    if (mid + 1 <= rq)
        updateRangeAi(2 * node + 1, mid + 1, right, lq, rq, val);

    ai[node].val = min(ai[2 * node].val, ai[2 * node + 1].val);
}

void updateAi(int node, int left, int right, int pos, int val) {
    if (left == right) {
        ai[node].val = val;
        return;
    }

    lazyUpdate(node);
    int mid = (left + right) / 2;
    if (pos <= mid)
        updateAi(2 * node, left, mid, pos, val);
    else
        updateAi(2 * node + 1, mid + 1, right, pos, val);
    ai[node].val = min(ai[2 * node].val, ai[2 * node + 1].val);
}

// void printAi() {
//     for (int i = 0; i <= n; ++i) {
//         int val = INF;
//         queryAi(1, 0, n, i, i, val);
//         cout << val << " ";
//     }
//     cout << "\n";
// }

int main() {
    ios::sync_with_stdio(0);

    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> b[i];

    cin >> nq;
    for (int i = 1; i <= nq; ++i) {
        int l, r;
        cin >> l >> r;
        qs[l].push_back(r);
    }

    for (int i = 0; i <= n; ++i)
        aiInit[i] = INF;

    aiInit[0] = (b[1] == 1);
    for (auto r: qs[1])
        aiInit[r] = (b[1] == 0);
    
    buildAi(1, 0, n);

    for (int i = 2; i <= n; ++i) {
        vector<pair<int, int>> updates;

        int valm1 = INF;
        queryAi(1, 0, n, i - 2, i - 1, valm1);
        valm1 += (b[i] == 1);
        updates.push_back(make_pair(i - 1, valm1));
        
        for (auto r: qs[i]) {
            int val = INF;
            queryAi(1, 0, n, i - 2, r, val);
            val += (b[i] == 0);
            updates.push_back(make_pair(r, val));
        }

        if (b[i] == 0)
            updateRangeAi(1, 0, n, i, n, 1);

        for (auto &x: updates)
            updateAi(1, 0, n, x.first, x.second);
    }

    int ans = INF;
    queryAi(1, 0, n, n - 1, n, ans);

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 17140