// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T, typename L>
class LazySegmentTree {
private:
    using Merge = function<T(T, T)>;
    using Apply = function<T(T, L)>;
    using Update = function<L(L, L)>;
    using CalcLazyValue = function<L(ssize_t, ssize_t, L)>;
    using Prop = function<L(L)>;

    size_t arr_size;
    T init_node;
    L init_lazy;
    vector<T> node;
    vector<L> lazy;
    vector<bool> lazy_flag;
    Merge merge_node;
    Apply apply_lazy_value;
    Update update_lazy_value;
    CalcLazyValue calc_lazy_value;
    Prop prop_lazy_value;
    
public:
    LazySegmentTree(vector<T> v, 
                    T init_node,
                    L init_lazy, 
                    Merge merge_node,
                    Apply apply_lazy_value,
                    Update update_lazy_value,
                    CalcLazyValue calc_lazy_value,
                    Prop prop_lazy_value = [](L l) { return l; })
        : init_node(init_node),
          init_lazy(init_lazy),
          merge_node(merge_node),
          apply_lazy_value(apply_lazy_value),
          update_lazy_value(update_lazy_value),
          calc_lazy_value(calc_lazy_value),
          prop_lazy_value(prop_lazy_value)
    {
        {
            arr_size = 1;
            while(arr_size < v.size()) arr_size *= 2;
        }
        node.resize(2 * arr_size - 1, init_node);
        lazy.resize(2 * arr_size - 1, init_lazy);
        lazy_flag.resize(2 * arr_size - 1, false);
        for(ll i = 0; i < v.size(); i++) node[i + arr_size - 1] = v[i];
        for(ll i = arr_size - 2; 0 <= i; i--) node[i] = merge_node(node[i * 2 + 1], node[i * 2 + 2]);
    }

    void lazy_eval(ll pos, ll left, ll right) {
        if(!lazy_flag[pos]) return;

        node[pos] = apply_lazy_value(node[pos], lazy[pos]);
        lazy_flag[pos] = false;

        if(right - left > 1) {
            for(ll idx = 2 * pos + 1; idx <= 2 * pos + 2; idx++) {
                lazy[idx] = update_lazy_value(lazy[idx], prop_lazy_value(lazy[pos]));
                lazy_flag[idx] = true;
            }
        }

        lazy[pos] = init_lazy;
    }

    void update_query(ll left, ll right, L val, ll pos = 0, ll node_left = 0, ll node_right = -1) {
        if(node_right < 0) node_right = arr_size;

        lazy_eval(pos, node_left, node_right);

        if(right <= node_left || node_right <= left) return;
        
        if(left <= node_left && node_right <= right) {
            lazy[pos] = calc_lazy_value(node_left, node_right, val);
            lazy_flag[pos] = true;
            lazy_eval(pos, node_left, node_right);
        } else {
            ll mid = (node_left + node_right) / 2;
            update_query(left, right, val, 2 * pos + 1, node_left, mid);
            update_query(left, right, val, 2 * pos + 2, mid, node_right);
            node[pos] = merge_node(node[2 * pos + 1], node[2 * pos + 2]);
        }
    }

    T get_query(ll left, ll right, ll pos = 0, ll node_left = 0, ll node_right = -1) {
        if(node_right < 0) node_right = arr_size;
        
        lazy_eval(pos, node_left, node_right);

        if(node_right <= left || right <= node_left) return init_node;
        if(left <= node_left && node_right <= right) return node[pos];

        ll mid = (node_left + node_right) / 2;
        return merge_node(get_query(left, right, 2 * pos + 1, node_left, mid),
                          get_query(left, right, 2 * pos + 2, mid, node_right));
    }
};

const ll inf = 5e15;

int main() {
    ll N;
    cin >> N;
    V<ll> B(N);
    for (ll &e : B) cin >> e;
    V<ll> sum0(N + 1), sum1(N + 1);
    for (ll i = 0; i < N; i++) {
        sum0[i + 1] = sum0[i] + (B[i] == 0);
        sum1[i + 1] = sum1[i] + (B[i] == 1);
    }

    LazySegmentTree<ll, ll> seg(sum1, inf, 0,
                                [](ll a, ll b) { return min(a, b); },
                                [](ll a, ll b) { return a + b; },
                                [](ll a, ll b) { return a + b; },
                                [](ll l, ll r, ll v) { return v; }),
                            seg_r(sum1, inf, 0,
                                  [](ll a, ll b) { return min(a, b); },
                                  [](ll a, ll b) { return a + b; },
                                  [](ll a, ll b) { return a + b; },
                                  [](ll l, ll r, ll v) { return v; });

    ll Q;
    cin >> Q;
    V<PLL> lr(Q);
    for (auto &&e : lr) {
        ll l, r;
        cin >> l >> r;
        e = PLL(l - 1, r);
    }
    sort(ALL(lr));

    auto update_v = [](LazySegmentTree<ll, ll> &seg, ll idx, ll v) {
        ll cur_v = seg.get_query(idx, idx + 1);
        seg.update_query(idx, idx + 1, -cur_v + min(cur_v, v));
    };

    ll cur_l = 0;

    auto update_l = [&](ll l) {
        while (cur_l < l) {
            seg.update_query(0, cur_l + 1, B[cur_l]);
            seg_r.update_query(cur_l + 1, N + 1, !B[cur_l]);
            cur_l++;
            DEBUG(make_tuple(cur_l, seg_r.get_query(cur_l, cur_l + 1)));
            update_v(seg, cur_l, seg_r.get_query(cur_l, cur_l + 1));
        }
    };

    for (auto &&e : lr) {
        ll l, r;
        tie(l, r) = e;
        update_l(l);
        DEBUG(cur_l);
        ll add_v = sum0[r] - sum0[l];
        ll minv = min(seg.get_query(0, l + 1), seg_r.get_query(l, r + 1)) + add_v;
        DEBUG(make_tuple(e, add_v, minv));
        update_v(seg_r, r, minv - add_v);
    }

    update_l(N);

    cout << seg.get_query(0, N + 1) << endl;
    return 0;
}


Measured memory_bytes: 28260