fun main(args: Array<String>) = yorukatsu22d()

fun yorukatsu22d() {
    data class Card(val amount: Long, val value: Long)

    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toLong() }
    val bcList = (1..m).map {
        readLine()!!.split(' ').map { it.toLong() }.let { Card(it[0], it[1]) }
    }

    val cards = (aList.groupBy { it }.map { Card(it.value.size.toLong(), it.key) } + bcList)
        .sortedByDescending { it.value }.toTypedArray()

    var remainToTake = n.toLong()
    var answer = 0L

    for ((amount, value) in cards) {
        if (remainToTake <= amount) {
            answer += remainToTake * value
            break
        } else {
            answer += amount * value
            remainToTake -= amount
        }
    }

    println(answer)
}
