import java.lang.Math.*
fun main(args:Array<String>?): Unit {
    val (_, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val beauties = readLine()!!.trim().split(' ').map(String::toLong)
    val constraint = Array(m){
        val (left, right) = readLine()!!.trim().split(' ').map(String::toInt)
        Pair(left - 1, right - 1)
    }
    println(
            solve(beauties, constraint)
    )
}

fun solve(beauties: List<Long>, constraint: Array<Pair<Int, Int>>): Long {
    val memo = Array(beauties.size){-1L}
    val sortedConstraint = constraint.sortedBy{it.first}
    val rights = sortedConstraint.map{it.second}.toMutableList()
    for (i in 1 until rights.size){
        rights[i] = max(rights[i], rights[i - 1])
    }
    fun sub(pos: Int, const: Int, constPosition: Int = 0): Long {
        return when{
            pos >= memo.size -> 0
            memo[pos] >= 0 -> memo[pos]
            constPosition < sortedConstraint.size && sortedConstraint[constPosition].first <= pos -> {
                val right = lowerBound(constPosition, sortedConstraint.size){next ->
                    pos < sortedConstraint[next].first
                }
                sub(pos, rights[right - 1], right)
            }
            const <= pos -> {
                memo[pos] = sub(pos + 1, pos + 1, constPosition) + beauties[pos]
                return memo[pos]
            }
            else -> {
                memo[pos] = max(sub(const + 1, const + 1, constPosition) + beauties[pos], sub(pos + 1, const, constPosition))
                memo[pos]
            }
        }
    }
    for (i in beauties.indices.step(100).reversed()){
        val r = lowerBound(0, sortedConstraint.size){pos ->
            i < sortedConstraint[pos].first
        }
        if (r == 0){
            sub(i, i, r)
        }else {
            sub(i, rights[r - 1], r)
        }
    }
    return sub(0, 0, 0)
}
inline fun lowerBound(from: Int, until: Int, predicate: (Int) -> Boolean): Int {
    var left = from
    var right = until
    while(left < right){
        val mid = (left + right) / 2
        if (predicate(mid)){
            right = mid
        }else {
            left = mid + 1
        }
    }
    return right
}
