fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val A = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    val BAndC = mutableListOf<Pair<Int, Long>>()
    (1..M).forEach {
        val (b, c) = readLine()!!.split(" ").map { it.toLong() }
        BAndC.add(Pair(b.toInt(), c))
    }

    A.sort()

    // Sort By C
    BAndC.sortBy { it.second * - 1}


    // O(NLOGN)
    var sum = 0L
    var position = 0
    BAndC.forEachIndexed { index, pair ->
        val b = pair.first
        val c = pair.second

        if (position >= N) {
            println(sum)
            return
        }

        //c　以上
        val upperBoundIndex = lowerBound(A.subList(position, N), c) - 1
        if (upperBoundIndex >= 0) {
            val replacableSize = upperBoundIndex + 1
            val replace = Math.min(replacableSize, b)!!

            val nextPosition = Math.min(position + replace, N)
            val replacedSize = nextPosition - position

            sum += replacedSize * c
            position = nextPosition
        }
    }
    sum += A.subList(position, N).sum()
    println(sum)
}
fun lowerBound(sortedList: List<Long>, key: Long) : Int {
    var ng = - 1 // left
    var ok = sortedList.size  // right

    fun isOk(mid: Int) : Boolean {
        return sortedList.get(mid) >= key
    }

    while (Math.abs(ok - ng) > 1) {
        var mid = (ok + ng) / 2
        if (isOk(mid)) {
            ok = mid
        } else {
            ng = mid
        }
    }
    return ok
}
