#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#ifdef LOCAL
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define dbg(...) 17;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) { bool f = true; os << "{"; for (const auto &x : c) { if (!f) os << ", "; f = false; os << x; } return os << "}"; }
template<typename T> void debug(string s, T x) { cerr << s << " = " << x << "\n"; }
template<typename T, typename... Args> void debug(string s, T x, Args... args) { cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...); }
const int INF = 1e6;
template<class T, int SZ> struct lazy_seg {
    T mn[2 * SZ], lazy[2 * SZ];
    lazy_seg() {
        for (int i = 0; i < 2 * SZ; i++) {
            mn[i] = INF;
            lazy[i] = INF;
        }
    }
    void push(int ind, int L, int R) {
        mn[ind] = min(mn[ind], lazy[ind]);
        if (L != R) {
            lazy[2 * ind] = min(lazy[2 * ind], lazy[ind]);
            lazy[2 * ind + 1] = min(lazy[2 * ind + 1], lazy[ind]);
        }
        lazy[ind] = INF;
    }
    void pull(int ind) {
        mn[ind] = min(mn[2 * ind], mn[2 * ind + 1]);
    }
    void build() {
        for (int i = SZ - 1; i >= 1; i--) {
            pull(i);
        }
    }
    void upd(int lo, int hi, T inc, int ind = 1, int L = 0, int R = SZ - 1) {
        push(ind, L, R);
        if (hi < L || R < lo) return ;
        if (lo <= L && R <= hi) {
            lazy[ind] = inc;
            push(ind, L, R);
            return;
        }
        int M = (L + R) / 2;
        upd(lo, hi, inc, 2 * ind, L, M);
        upd(lo, hi, inc, 2 * ind + 1, M + 1, R);
        pull(ind);
    }
    T qmin(int lo, int hi, int ind = 1, int L = 0, int R = SZ - 1) {
        push(ind, L, R);
        if (lo > R || L > hi) return INF;
        if (lo <= L && R <= hi) return mn[ind];
        int M = (L + R) / 2;
        return min(qmin(lo, hi, 2 * ind, L, M), qmin(lo, hi, 2 * ind + 1, M + 1, R));
    }
};
int main() {
    int n; cin >> n;
    vector<int> b(n);
    for (int i = 0; i < n; i++) cin >> b[i];
    int q; cin >> q;
    vector<vector<int>> ed(n);
    for (int i = 0; i < q; i++) {
        int l, r; cin >> l >> r;
        l--; r--;
        ed[r].push_back(l);
    }
    vector<int> one(n);
    vector<int> zero(n);
    vector<int> dp(n);
    for (int i = 0; i < n; i++) {
        if (i == 0) one[i] = b[i], zero[i] = (b[i] ^ 1);
        else one[i] = one[i - 1] + b[i], zero[i] = zero[i - 1] + (b[i] ^ 1);
    }
    lazy_seg<int, (1 << 18)> cover;
    lazy_seg<int, (1 << 18)> blank;
    auto ones = [&](int l, int r) -> int {
        if (l > r) return 0;
        return one[r] - (l == 0 ? 0 : one[l - 1]);
    };
    auto zeros = [&](int l, int r) -> int {
        if (l > r) return 0;
        return zero[r] - (l == 0 ? 0 : zero[l - 1]);
    };
    int ans = ones(0, n - 1);
    for (int r = 0; r < n; r++) {
        for (int l: ed[r]) {
            int case_one = zeros(l, r) + (l == 0 ? 0 : one[l - 1] + min(0, blank.qmin(0, l - 1)));
            int case_two = zero[r] + cover.qmin(l, l);
            int res = min(case_one, case_two);
            ans = min(ans, res + ones(r + 1, n - 1));
            blank.upd(r, r, res - one[r]);
            cover.upd(l, r, res - zero[r]);
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 24040