import java.util.*

fun main(args:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val q = PriorityQueue<Long>()
    var ans = 0L
    readLine()!!.split(" ").map { it.toLong() }.forEach {
        ans += it
        q.add(it)
    }
    val sousa = (1..m).map { readLine()!!.split(" ").map { it.toLong() } }.sortedByDescending { it[1] }
    (0 until m).forEach {
        val (b, c) = sousa[it]
        for(i in (1 .. b)) {
            if(q.peek() >= c) {
                break
            }
            val num = q.poll()
            ans += c-num
            q.add(c)
        }
    }
    println(ans)
}

