object Main extends App {
  val n = io.StdIn.readInt()
  val seq: Seq[Int] = io.StdIn.readLine().split(" ").map(_.toInt)
  val Q = io.StdIn.readInt()
  val cache: Array[Int] = Array.fill(n)(0)
  var diff: Int = seq.count(_ == 1)

  for(_ <- 0 until Q) {
    val Seq(l, r): Seq[Int] = io.StdIn.readLine().split(" ").map(_.toInt)
    val score = (l-1 until r).foldLeft(0)((acc, i) =>
      acc + (
        if (seq(i) == 1 && cache(i) == 0) 1
        else if (seq(i) == 0 && cache(i) == 0) -1
        else 0
        )
    )
    if (score > 0) {
      (l-1 until r) foreach {cache.update(_, 1)}
      diff -= score
    }
  }

  println(diff)
}