import heapq

N, M = list(map(int, input().split()))

nums = list(map(int, input().split()))

n = len(nums)

heap = []

for i in range(M):

    B, C = list(map(int, input().split()))

    heap.append([-C, B])

for num in nums:

    heap.append([-num, 1])

s = 0

heapq.heapify(heap)

while n > 0:

    num, cnt = heapq.heappop(heap)

    num = num * -1

    s += num * min(cnt, n)

    n -= min(cnt, n)

print(s)
def getInput():

    return [int(x) for x in input().split()]



N, M = getInput()

nums = getInput()

nums = sorted(nums)

rep = []

for i in range(M):

    b, c = getInput()

    rep.append((b, c))

rep = sorted(rep, key=lambda x: x[1], reverse=True)

ans = 0

minIndex = 0

isFinished = False

for b, c in rep:

    for _ in range(b):

        if minIndex < len(nums) and nums[minIndex] < c:

            ans += c

            minIndex += 1

        else:

            isFinished = True

            break

    

    if isFinished:

        break

if minIndex < len(nums):

    ans += sum(nums[minIndex:])

print(ans)
import heapq

N, M = list(map(int, input().split()))
nums = list(map(int, input().split()))
n = len(nums)
heap = []
for i in range(M):
    B, C = list(map(int, input().split()))
    heap.append([-C, B])
for num in nums:
    heap.append([-num, 1])
s = 0
heapq.heapify(heap)
while n > 0:
    num, cnt = heapq.heappop(heap)
    num = num * -1
    s += num * min(cnt, n)
    n -= min(cnt, n)
print(s)

def getInput():
    return [int(x) for x in input().split()]


N, M = getInput()
nums = getInput()
nums = sorted(nums)
rep = []
for i in range(M):
    b, c = getInput()
    rep.append((b, c))
rep = sorted(rep, key=lambda x: x[1], reverse=True)
ans = 0
minIndex = 0
isFinished = False
for b, c in rep:
    for _ in range(b):
        if minIndex < len(nums) and nums[minIndex] < c:
            ans += c
            minIndex += 1
        else:
            isFinished = True
            break
    if isFinished:
        break
if minIndex < len(nums):
    ans += sum(nums[minIndex:])
print(ans)

-import heapq +def getInput(): +    return [int(x) for x in input().split()] -N, M = list(map(int, input().split())) -nums = list(map(int, input().split())) -n = len(nums) -heap = [] + +N, M = getInput() +nums = getInput() +nums = sorted(nums) +rep = [] -    B, C = list(map(int, input().split())) -    heap.append([-C, B]) -for num in nums: -    heap.append([-num, 1]) -s = 0 -heapq.heapify(heap) -while n > 0: -    num, cnt = heapq.heappop(heap) -    num = num * -1 -    s += num * min(cnt, n) -    n -= min(cnt, n) -print(s) +    b, c = getInput() +    rep.append((b, c)) +rep = sorted(rep, key=lambda x: x[1], reverse=True) +ans = 0 +minIndex = 0 +isFinished = False +for b, c in rep: +    for _ in range(b): +        if minIndex < len(nums) and nums[minIndex] < c: +            ans += c +            minIndex += 1 +        else: +            isFinished = True +            break +    if isFinished: +        break +if minIndex < len(nums): +    ans += sum(nums[minIndex:]) +print(ans)