#include <assert.h>

#include <cstring>
#include <cstdio>
#include <list>
#include <bitset>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <complex>

using namespace std;

typedef long long int64;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int > vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;

#define ALL(x) (x).begin(), (x).end()
#define CLEAR(x) (x).clear()
#define RESET(x) memset((x), 0, sizeof (x))

#define FOR(i, b, e) for ( int i = (b); i < (e); ++i)
#define RE(i, n) FOR(i, 0, (n))
#define FOREACH(i, x, y) for ( int i = (x); i <= (y); ++i)

#define SIZE(X) ((int)(X.size())) //NOTES:SIZE(
#define LENGTH(X) ((int)(X.length())) //NOTES:LENGTH(
#define MP(X,Y) make_pair(X,Y)//NOTES:MP(

typedef long long int64; //NOTES:int64
typedef unsigned long long uint64;//NOTES:uint64
#define two(X) (1<<(X))//NOTES:two(
#define twoL(X) (((int64)(1))<<(X)) //NOTES:twoL(
#define contain(S,X) (((S)&two(X))!=0)//NOTES:contain(
#define containL(S,X) (((S)&twoL(X))!=0)//NOTES:containL(
#define chkmax(X, Y) (X) = max((X), (Y))
#define chkmin(X, Y) (X) = min((X), (Y))

const ll maxn = (ll)2e5 + 100;
const ll maxm = (ll)1e3;
const double PI = acos(-1.0);

const int mod = 1e9 + 7;
const int rev = (mod + 1) / 2;

ll d[maxn * 4];

const int INF = 1e9;
void Build(int root, int l, int r) {
    RE(i, maxn * 4) d[i] = INF;
}

void Update(int root, int l, int r, int x, ll v) {
    if (l == r) {
        chkmin(d[root], v);
        return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) {
        Update(root << 1, l, mid, x, v);
    } else {
        Update(root << 1 | 1, mid + 1, r, x, v);
    }
    chkmin(d[root], d[root << 1]);
    chkmin(d[root], d[root << 1 | 1]);
}

ll Query(int root, int l, int r, int LL, int RR) {

    if (LL <= l && r <= RR) {
        return d[root];
    }
    int mid = (l + r) >> 1;
    long long ans = INF;
    if (LL <= mid) {
        chkmin(ans, Query(root << 1, l, mid, LL, RR));
    }
    if (mid < RR) {
        chkmin(ans, Query(root << 1 | 1, mid + 1, r, LL, RR));
    }
    return ans;
}

vi ri[maxn];

int main() {
#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;
    while (scanf("%d", &n) != EOF) {
        vi b(n + 1, 0);
        int cnt0 = 0;
        RE(i, n) scanf("%d", &b[i + 1]), cnt0 += (b[i + 1] == 0);

        Build(1, 0, n);

        int m;
        scanf("%d", &m);
        vpii qs(m);
        RE(i, m) { scanf("%d%d", &qs[i].first, &qs[i].second); }
        sort(ALL(qs));

        RE(i, maxn) ri[i].resize(0);
        for (auto p : qs) ri[p.first].push_back(p.second);

        vll dp(n + 1, INF);
        dp[0] = 0;
        Update(1, 0, n, 0, 0);
        FOREACH(i, 1, n) {
            for (auto r : ri[i]) {
                int res = Query(1, 0, n, i - 1, r);
                if (dp[r] > res) {
                    dp[r] = res;
                    Update(1, 0, n, r, dp[r]);
                }
            }
            chkmin(dp[i], dp[i - 1] + (b[i] ? 1 : -1));
            Update(1, 0, n, i, dp[i]);
        }
        printf("%lld\n", dp[n] + cnt0);
    }
    return 0;
}

Measured memory_bytes: 19072