fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { ij -> ij.toInt() }
    val a = readLine()!!.split(" ").map { ij -> ij.toLong() }
    val ar = arrayListOf<Long>()
    
    val map = mutableMapOf<Long, Long>()
    val seq = mutableListOf<Long>()
    
    for (i in 0 until m) {
        val (b, c) = readLine()!!.split(" ").map { it.toLong() }
        if (map.containsKey(c)) {
            map[c] = map[c]!! + b
        } else {
            map[c] = b
            seq.add(c)
        }
    }
    
    for (i in a.indices) {
        if (map.containsKey(a[i])) {
            map[a[i]] = map[a[i]]!! + 1
        } else {
            map[a[i]] = 1
            seq.add(a[i])
        }
    }
    
    val s = seq.sorted().reversed()
    var collected = 0L
    
    var ans = 0L
    
    for (i in s.indices) {
        if (collected < n) {
            val mn = Math.min(n - collected, map[s[i]]!!)
            ans += mn * s[i]
//            print("$mn*${s[i]} ")
            collected += mn
        }
    }
    
    
    
//    println()
    
//    println(s)
//    println(map)

//    ar.sort()
//    ar.reverse()
    
    println(ans)
}
