import os, sys, re, math, heapq



N, M = [int(s) for s in input().split(' ')]



dic = {}

cards =  [int(s) for s in input().split(' ')]

for c in cards:

    if c in dic:

        dic[c] += 1

    else:

        dic[c] = 1



for i in range(M):

    b,c = [int(s) for s in input().split(' ')]

    if c in dic:

        dic[c] += b

    else:

        dic[c] = b



keys = sorted(list(dic.keys()), reverse=True)



ret = 0

for k in keys:

    ret += min(N, dic[k]) * k

    N = N - dic[k]

    if N <= 0:

        break



print(ret)

import os, sys, re, math, queue



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

A = list(map(int,input().split(' ')))



memo = {}

for a in A:

	if a in memo:

		memo[a] += 1

	else:

		memo[a] = 1



for _ in range(M):

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

	if C in memo:

		memo[C] += B

	else:

		memo[C] = B



ret = 0

cnt = 0



key_ary = sorted(list(memo.keys()),reverse=True)

for k in key_ary:

	tmp = memo[k]

	if cnt + tmp <= N:

		ret += k * tmp

		cnt += tmp

		if cnt >= N:

			break

	else:

		ret += k * (N - cnt)

		break

	

print(ret)
import os, sys, re, math, heapq

N, M = [int(s) for s in input().split(" ")]
dic = {}
cards = [int(s) for s in input().split(" ")]
for c in cards:
    if c in dic:
        dic[c] += 1
    else:
        dic[c] = 1
for i in range(M):
    b, c = [int(s) for s in input().split(" ")]
    if c in dic:
        dic[c] += b
    else:
        dic[c] = b
keys = sorted(list(dic.keys()), reverse=True)
ret = 0
for k in keys:
    ret += min(N, dic[k]) * k
    N = N - dic[k]
    if N <= 0:
        break
print(ret)

import os, sys, re, math, queue

N, M = list(map(int, input().split(" ")))
A = list(map(int, input().split(" ")))
memo = {}
for a in A:
    if a in memo:
        memo[a] += 1
    else:
        memo[a] = 1
for _ in range(M):
    B, C = list(map(int, input().split(" ")))
    if C in memo:
        memo[C] += B
    else:
        memo[C] = B
ret = 0
cnt = 0
key_ary = sorted(list(memo.keys()), reverse=True)
for k in key_ary:
    tmp = memo[k]
    if cnt + tmp <= N:
        ret += k * tmp
        cnt += tmp
        if cnt >= N:
            break
    else:
        ret += k * (N - cnt)
        break
print(ret)

-import os, sys, re, math, heapq +import os, sys, re, math, queue -N, M = [int(s) for s in input().split(" ")] -dic = {} -cards = [int(s) for s in input().split(" ")] -for c in cards: -    if c in dic: -        dic[c] += 1 +N, M = list(map(int, input().split(" "))) +A = list(map(int, input().split(" "))) +memo = {} +for a in A: +    if a in memo: +        memo[a] += 1 -        dic[c] = 1 -for i in range(M): -    b, c = [int(s) for s in input().split(" ")] -    if c in dic: -        dic[c] += b +        memo[a] = 1 +for _ in range(M): +    B, C = list(map(int, input().split(" "))) +    if C in memo: +        memo[C] += B -        dic[c] = b -keys = sorted(list(dic.keys()), reverse=True) +        memo[C] = B -for k in keys: -    ret += min(N, dic[k]) * k -    N = N - dic[k] -    if N <= 0: +cnt = 0 +key_ary = sorted(list(memo.keys()), reverse=True) +for k in key_ary: +    tmp = memo[k] +    if cnt + tmp <= N: +        ret += k * tmp +        cnt += tmp +        if cnt >= N: +            break +    else: +        ret += k * (N - cnt)