fun main(args: Array<String>) {
    val (n, m) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val a = readLine()?.split(" ")?.map(String::toLong)?.sorted() ?: return
    val b = 0.until(m).map {
        val (b, c) = readLine()?.split(" ")?.map(String::toLong) ?: return
        Pair(b, c)
    }.sortedBy { -it.second }

    var j = 0
    var r = b[j].first
    var t = 0L
    0.until(n).forEach { i ->
        val aa = a[i]
        val bb = if (r > 0L) {
            b[j].second
        } else {
            0L
        }
        if (aa > bb) {
            t += aa
        } else {
            r--
            if (r == 0L) {
                if (j + 1 < b.size) {
                    j++
                    r = b[j].first
                }
            }
            t += bb
        }
    }
    println(t.toString())
}
