#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int n_ = 200000+2;
const int sz_ = (1<<18);

int n, q, a[n_], s[n_], z[n_];
int d[n_];
int tree[sz_+sz_];
vector<int> v[n_];

void update(int s, int e, int x) {
    s += sz_, e += sz_;
    while (s <= e) {
        tree[s] = min(tree[s], x);
        tree[e] = min(tree[e], x);
        s  = (s+1)>>1, e = (e-1)>>1;
    }
}

int query(int i) {
    int r = 1e9;
    i += sz_;
    while (i) {
        r = min(r, tree[i]);
        i >>= 1;
    }
    return r;
}

int main() {
    for (int i = 1; i < sz_+sz_; i++) {
        tree[i] = 1e9;
    }
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        s[i] = s[i-1] + 1 - a[i];
    }
    scanf("%d", &q);
    while (q--) {
        int l, r;
        scanf("%d %d", &l, &r);
        v[r].push_back(l);
    }

    for (int i = 1; i <= n; i++) {
        update(i-1, i-1, d[i-1]-s[i-1]);
        d[i] = d[i-1] + a[i];
        for (int l : v[i]) {
            update(l, i, query(l-1));
        }
        d[i] = min(d[i], query(i)+s[i]);
    }

    //puts("");

    printf("%d\n", d[n]);

    return 0;
}