import Foundation

let args = readLine()!.split(separator: " ")
let N = Int(args[0])!
let M = Int(args[1])!

var minA = Int.max
var maxA = 0
var values: [Int: Int] = [:]

readLine()!.split(separator: " ").forEach {
    let a = Int($0)!
    values[a] = 1 + (values[a] ?? 0)
    minA = min(minA, a)
    maxA = max(maxA, a)
}

for _ in 1 ... M { // j
    let args = readLine()!.split(separator: " ")
    var b = Int(args[0])!
    let c = Int(args[1])!
    while b > 0 {
        let a = minA
        if a < c {
            let count = min(values[a]!, b)
            values[a]! -= count
            values[c] = count + (values[c] ?? 0)
            if values[a] == 0 {
                values[a] = nil
            }
            while values[minA] == nil {
                minA += 1
            }
            b -= count
        } else {
            b = 0
        }
    }
    maxA = max(maxA, c)
}

let answer = values.reduce(0, { $0 + $1.key * $1.value })

print(answer)
