local N, M = io.read("n", "n")
local A = {}
for i=1,N do
    A[i] = io.read("n")
end
local T = {}
for i=1,M do
    local b, c = io.read("n", "n")
    T[i] = {b, c}
end
table.sort(A)
table.sort(T, function(x, y) return x[2] > y[2] end)

local card_idx = 1
for i=1, M do
    local b, c = table.unpack(T[i])
    for j = card_idx, math.min(card_idx + b - 1, N) do
        if A[j] < c then
            A[j] = c
        end
    end
    card_idx = card_idx + b
end

local sum = 0
for i=1,N do
    sum = sum + A[i]
end
print(sum)
