import java.util.Scanner

case class Input(as: Vector[Long], lrs: Vector[(Int, Int)]) {
  val n = as.length
  val m = lrs.length

  def conflict: Vector[Int] = {
    val res: Array[Int] = (0 until n).toArray
    lrs.foreach({ case (l, r) => res(r) = math.min(res(r), l) })
    (0 until n-1).reverse.foreach(i => res(i) = math.min(res(i), res(i+1)))
    res.toVector
  }

  def solved: Output = {
    val conf = conflict
    val dp: Array[Long] = Array.fill(n+1)(0)
    (1 to n).foreach(i => dp(i) = math.max(dp(i-1), dp(conf(i-1))+as(i-1)))
    Output(dp(n))
  }
}

object Input {
  def fromStdin(): Input = {
    val sc = new Scanner(System.in)
    def nextPair() = (sc.nextInt()-1, sc.nextInt()-1)
    val n = sc.nextInt()
    val m = sc.nextInt()
    Input(Vector.fill(n)(sc.nextLong), Vector.fill(m)(nextPair))
  }
}

case class Output(v: Long) {
  override def toString(): String = {
    v.toString()
  }

  def print() = println(this.toString())
}

object Main extends App {
  Input.fromStdin().solved.print()
}

