#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

template<typename T> T inf;
template<> constexpr int inf<int> = 1e9;
template<> constexpr ll inf<ll> = 1e18;
template<> constexpr ld inf<ld> = 1e30;

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

// template <typename T>
// class StarrySkyTree {
//   const int n;
//   vector<T> data, lazy;
//   int expand(int n) const { return n == 1 ? n : expand((n + 1) / 2) * 2; }
// public:
//   StarrySkyTree(int m) : n(expand(m)), data(n * 2, 0), lazy(n * 2, 0) {}
//   void add(int l, int r, T val) {
//     l += n; r += n;
//     const int left = l, right = r;
//     while (l != r) {
//       if (l % 2) { lazy[l] += val; data[l++] += val; }
//       if (r % 2) { lazy[--r] += val; data[r] += val; }
//       l /= 2; r /= 2;
//     }
//     l = left; r = right - 1;
//     while (l /= 2, r /= 2) {
//       data[l] = min(data[l * 2], data[l * 2 + 1]) + lazy[l];
//       data[r] = min(data[r * 2], data[r * 2 + 1]) + lazy[r];
//     }
//   }
//   T minimum(int l, int r) const {
//     l += n; r += n;
//     T res1 = inf<T>, res2 = inf<T>;
//     while (l != r) {
//       if (l % 2) res1 = min(res1, data[l++]);
//       if (r % 2) res2 = min(res2, data[--r]);
//       l /= 2; r /= 2; res1 += lazy[l - 1]; res2 += lazy[r];
//     }
//     --l;
//     while (l /= 2, r /= 2) { res1 += lazy[l]; res2 += lazy[r]; }
//     return min(min(res1, res2), inf<T>);
//   }
// };

using Data = int;

struct StarrySky {
  static const int MAX_DEPTH = 19;
  static const int STsize = 1 << MAX_DEPTH;
  Data data[STsize];
  Data lazy[STsize]; int n;
  StarrySky(void) : n(STsize / 2) {
    REP(i,STsize) data[i] = lazy[i] = 0;
  }
  void add(int fr, int to, Data val) { upd_sub(fr, to, 2*n-2, 0, n, val); }
  Data minimum(int fr, int to) { return min_sub(fr, to, 2*n-2, 0, n); }
private:
  void upd_sub(int fr, int to, int node, int la, int ra, Data val) {
    if (ra<=fr || to<=la) return;
    if (fr<=la && ra<=to) { lazy[node] += val; return; }
    int left = (node - n) * 2, right = left + 1;
    upd_sub(fr, to, left, la, (la+ra)/2, val);
    upd_sub(fr, to, right, (la+ra)/2, ra, val);
    data[node] = min(data[left] + lazy[left], data[right] + lazy[right]);
  }
  Data min_sub(int fr, int to, int node, int la, int ra) {
    if (ra<=fr || to<=la) return 0x7FFFFFFF;
    if (fr<=la && ra<=to) return data[node] + lazy[node];
    Data vl = min_sub(fr, to, (node-n)*2+0, la, (la+ra)/2);
    Data vr = min_sub(fr, to, (node-n)*2+1, (la+ra)/2, ra);
    return lazy[node] + min(vl, vr);
  }
};

vector<int> rs[256000];

void solve(ll N, vector<ll> b, ll Q, vector<ll> l, vector<ll> r) {
  StarrySky seg;
  // StarrySkyTree<int> seg(N + 1);
  seg.add(1, N + 1, int(1e9));
  REP(i,Q) {
    rs[l[i] - 1].push_back(r[i]);
  }
  REP(i,N) {
    for (int r: rs[i]) {
      int mi = seg.minimum(0, r);
      int def = seg.minimum(r, r + 1);
      if (mi < def) seg.add(r, r + 1, mi - def);
      // cout << i << " " << r << " " << mi << " " << def << endl;
    }
    // cout << "ok" << endl;
    // REP(j,N+1) cout << seg.minimum(j, j + 1) << " ";
    // cout << endl;
    seg.add(0, i + 1, b[i]);
    // REP(j,N+1) cout << seg.minimum(j, j + 1) << " ";
    // cout << endl;
    seg.add(i + 1, N + 1, 1 - b[i]);
    // REP(j,N+1) cout << seg.minimum(j, j + 1) << " ";
    // cout << endl;
  }
  cout << seg.minimum(0, N + 1) << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	ll Q;
	scanf("%lld", &N);
	vector<ll> b(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &b[i]);
	}
	scanf("%lld", &Q);
	vector<ll> l(Q-1+1);
	vector<ll> r(Q-1+1);
	for (int i = 0 ; i <= Q-1 ; i++) {
	  scanf("%lld", &l[i]);
	  scanf("%lld", &r[i]);
	}
	solve(N, b, Q, l, r);
	return 0;
}


Measured memory_bytes: 25344