fun main(args: Array<String>) {
    val readInts = { readLine()!!.split(" ").map { it.toInt() } }

    val (n, m) = readInts()

    val a = readInts().toIntArray().sortedArray().reversedArray()

    val bc = (1..m).map {
        val (b, c) = readInts()
        b to c
    }.sortedByDescending { it.second }

    var sum = 0L
    var count = n
    var ap = 0
    var bcp = 0
    while (count > 0) {

        if (bcp != bc.size && a[ap] <= bc[bcp].second) {
            val (b, c) = bc[bcp]
            val num = Math.min(count, b)
            sum += num.toLong() * c
            bcp++
            count -= num
        } else {
            sum += a[ap]
            ap++
            count--
        }
    }

    println(sum)
}
