fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toLong() }
    val cb = mutableMapOf<Long,Int>()
    a.forEach {
        cb[it] = (cb[it]?:0)+1
    }
    repeat(m) {
        val (b,c) = readLine()!!.split(" ").map { it.toLong() }
        cb[c] = (cb[c]?:0)+b.toInt()
    }

    val x = cb.toList().sortedByDescending { it.first }
    var sum = 0L
    var count = 0
    var i = 0
    while(count<n){

        if(count+x[i].second<n){
            count += x[i].second
            sum += x[i].first * x[i].second
        }else{
            sum += (n-count) * x[i].first
            println(sum)
            break
        }
        i++
    }
}

