fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val xs = readLine()!!.split(' ').map { it.toLong() }.sorted().toMutableList()
    val ys = (0 until m).map {
        val (b, c) = readLine()!!.split(' ').map { it.toLong() }
        Pair(b.toInt(), c)
    }.sortedByDescending { it.second }

    var i = 0
    for (y in ys) {

        var j = 0
        while (j < y.first && i < n) {
            j++
            if (y.second > xs[i]) {
                xs[i] = y.second
                i++
            } else {
                i = n
            }
        }

        if (i == n) {
            break
        }
    }

    println(xs.sum())
}
