/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (win, osx, linux)
 * Author: step_by_step
 * Time: 2020-02-16 20:55:45
**/

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
  
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define prev fhsgfhjf
#define plus fsghsf
#define minus ytryr
  
using namespace std;
  
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
  
const int N = 200000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int cnt_v;
int tree[N * 4];
int upd[N * 4];

void build(int n) {
    cnt_v = 1;
    while (cnt_v < n) {
        cnt_v <<= 1;
    }
    fill(tree, tree + cnt_v * 2 - 1, inf);
    fill(upd, upd + cnt_v * 2 - 1, inf);
}

void push(int x) {
    setmin(tree[x * 2 + 1], upd[x]);
    setmin(upd[x * 2 + 1], upd[x]);
    setmin(tree[x * 2 + 2], upd[x]);
    setmin(upd[x * 2 + 2], upd[x]);
    upd[x] = inf;
}

void update_range(int x, int lx, int rx, int l, int r, int val) {
    if (lx >= r || l >= rx) {
        return;
    } else if (lx >= l && rx <= r) {
        setmin(tree[x], val);
        setmin(upd[x], val);
    } else {
        push(x);
        update_range(x * 2 + 1, lx, (lx + rx) / 2, l, r, val);
        update_range(x * 2 + 2, (lx + rx) / 2, rx, l, r, val);
        tree[x] = min(tree[x * 2 + 1], tree[x * 2 + 2]);
    }
}

int get(int x, int lx, int rx, int p) {
    if (rx - lx == 1) {
        return tree[x];
    } else {
        push(x);
        if (p < (lx + rx) / 2) {
            return get(x * 2 + 1, lx, (lx + rx) / 2, p);
        } else {
            return get(x * 2 + 2, (lx + rx) / 2, rx, p);
        }
    }
}

int b[N];
int pref[N + 1];

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 10.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    rep(i, 0, n) {
        cin >> b[i];
        pref[i + 1] = pref[i] + (b[i] == 0 ? 1 : 0);
    }
    build(n);
    int q;
    cin >> q;
    vector<int> st[n];
    rep(i, 0, q) {
        int l, r;
        cin >> l >> r; l--; r--;
        st[r].push_back(l);
    }
    rep(i, 0, n) {
        int val = pref[i] + (i > 0 ? get(0, 0, cnt_v, i - 1) : 0);
        val += b[i];
        update_range(0, 0, cnt_v, i, i + 1, val - pref[i + 1]);
        for (int j : st[i]) {
            val = pref[j] + (j > 0 ? get(0, 0, cnt_v, j - 1) : 0);
            update_range(0, 0, cnt_v, j, i + 1, val - pref[j]);
        }
        /*rep(j, 0, i + 1) {
            cout << pref[j + 1] + get(0, 0, cnt_v, j) << " ";
        }
        cout << endl;*/
    }
    cout << pref[n] + get(0, 0, cnt_v, n - 1) << "\n";
    return 0;
}

Measured memory_bytes: 17664