#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)

typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 2e5 + 5;
const int INF = 1e9;
const int off = 1 << 18;

int n, q, cnt;
vector <int> l[MAXN];
int dp[MAXN], a[MAXN];

struct Tournament{
    vector <point> t[2 * off];
    bool bio[2 * off];

    void build(int x){
        bio[x] = true;
        vector <point> v;
        sort(t[x].begin(), t[x].end());

        v.pb(point(0, INF));
        for(auto it : t[x])
            if(it.second < v.back().second)
                v.pb(it);
        t[x] = v;
    }

    void add(int x, int left, int val){
        x += off;
        while(x){
            t[x].pb(point(left, val));
            x >>= 1;
        }
    }

    int get(int x, int left){
        if(!bio[x])
            build(x);

        auto pos = lower_bound(t[x].begin(), t[x].end(), point(left, -INF));
        return (*(--pos)).second;
    }

    int query(int x, int lo, int hi, int a, int b){
        if(lo >= a && hi <= b)
            return get(x, a);
        if(lo >= b || hi <= a)
            return INF;

        int mid = (lo + hi) >> 1;
        int X = query(x * 2, lo, mid, a, b);
        int Y = query(x * 2 + 1, mid, hi, a, b);
        return min(X, Y);
    }
}T;

void load(){
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n;
    FOR(i, 1, n + 1)
        cin >> a[i];
    cin >> q;
    REP(i, q){
        int A, B; cin >> A >> B;
        l[B].pb(A);
    }
}

void solve(){
    FOR(i, 1, n + 1){
        cnt += 1 - a[i];

        for(auto it : l[i]){
            int val = min(T.query(1, 0, off, it, i), dp[it - 1]);
            T.add(i, it, val);
        }
        int add = a[i] == 1 ? 1 : -1;
        T.add(i, i, dp[i - 1] + add);
        T.build(i + off);
        dp[i] = T.t[i + off].back().second;
    }
    cout << dp[n] + cnt;
}

int main(){
    load();
    solve();
}
