output_description: Print the minimum possible hamming distance.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      b_1 b_2 ... b_N
      Q
      l_1 r_1
      l_2 r_2
      :
      l_Q r_Q
attempt: class segment_tree:
      def __init__(self, N, operator_M, e_M):
          self.op_M = operator_M
          self.e_M = e_M
  
          self.N0 = 1 << (N - 1).bit_length()
          self.dat = [self.e_M] * (2 * self.N0)
  
      # 長さNの配列 initial で初期化
      def build(self, initial):
          self.dat[self.N0 : self.N0 + len(initial)] = initial[:]
          for k in range(self.N0 - 1, 0, -1):
              self.dat[k] = self.op_M(self.dat[2 * k], self.dat[2 * k + 1])
  
      # a_k の値を x に更新
      def update(self, k, x):
          k += self.N0
          self.dat[k] = x
          k //= 2
          while k:
              self.dat[k] = self.op_M(self.dat[2 * k], self.dat[2 * k + 1])
              k //= 2
  
      # 区間[L,R]をopでまとめる
      def query(self, L, R):
          L += self.N0
          R += self.N0 + 1
          sl = sr = self.e_M
          while L < R:
              if R & 1:
                  R -= 1
                  sr = self.op_M(self.dat[R], sr)
              if L & 1:
                  sl = self.op_M(sl, self.dat[L])
                  L += 1
              L >>= 1
              R >>= 1
          return self.op_M(sl, sr)
  
      def get(self, k):  # k番目の値を取得。query[k,k]と同じ
          return self.dat[k + self.N0]
  
  
  # coding: utf-8
  # Your code here!
  import sys
  
  read = sys.stdin.read
  readline = sys.stdin.readline
  
  (n,) = map(int, readline().split())
  (*b,) = [0] + [*map(int, readline().split())]
  (q,) = map(int, readline().split())
  
  left = [[] for i in range(n + 1)]
  mp = map(int, read().split())
  for l, r in zip(mp, mp):
      left[r].append(l)
  
  from itertools import accumulate
  
  one = list(accumulate(b))
  
  """
  dp[i] = i までみたスコア（同じなら1点）の最大値
  
  
  
  """
  dp = segment_tree(n + 1, max, 0)
  
  for i in range(1, n + 1):
      if left[i]:
          v = min(left[i])
          res = max(one[i] - one[l - 1] + dp.query(0, l - 1) for l in left[i])  # 1にする
          res = max(
              res, (i - (v - 1)) - (one[i] - one[v - 1]) + dp.query(0, v - 1)
          )  # 0にする
          dp.update(i, res)
      else:
          res = (1 - b[i]) + dp.query(0, i - 1)
          dp.update(i, res)
  
  
  print(n - dp.get(n))
  
problem_description: Statement
  
  You are given a sequence a = \\{a_1, ..., a_N\\} with all zeros, and a
  sequence b = \\{b_1, ..., b_N\\} consisting of 0 and 1. The length of both is
  N.
  
  You can perform Q kinds of operations. The i-th operation is as follows:
  
    * Replace each of a_{l_i}, a_{l_i + 1}, ..., a_{r_i} with 1.
  
  Minimize the hamming distance between a and b, that is, the number of i such
  that a_i \neq b_i, by performing some of the Q operations.
samples: [{"input": "3\n    1 0 1\n    1\n    1 3", "output": "1\n    \n\nIf you choose to perform the operation, a will become \\\\{1, 1, 1\\\\}, for a\nhamming distance of 1.\n\n* * *"}, {"input": "3\n    1 0 1\n    2\n    1 1\n    3 3", "output": "0\n    \n\nIf both operations are performed, a will become \\\\{1, 0, 1\\\\}, for a hamming\ndistance of 0.\n\n* * *"}, {"input": "3\n    1 0 1\n    2\n    1 1\n    2 3", "output": "1\n    \n\n* * *"}, {"input": "5\n    0 1 0 1 0\n    1\n    1 5", "output": "2\n    \n\nIt may be optimal to perform no operation.\n\n* * *"}, {"input": "9\n    0 1 0 1 1 1 0 1 0\n    3\n    1 4\n    5 8\n    6 7", "output": "3\n    \n\n* * *"}, {"input": "15\n    1 1 0 0 0 0 0 0 1 0 1 1 1 0 0\n    9\n    4 10\n    13 14\n    1 7\n    4 14\n    9 11\n    2 6\n    7 8\n    3 12\n    7 13", "output": "5\n    \n\n* * *"}, {"input": "10\n    0 0 0 1 0 0 1 1 1 0\n    7\n    1 4\n    2 5\n    1 3\n    6 7\n    9 9\n    1 5\n    7 9", "output": "1"}]