from collections import Counter
N, M = map(int, input().split())
A = list(map(int, input().split()))

A = Counter(A)

for _ in range(M):
    b, c = map(int, input().split())
    A[c] += b

A = sorted(A.items(), key=lambda x: x[0], reverse=True)

ans = 0
for key, value in A:
    if N - value >= 0:
        ans += key * value
        N -= value
    else:
        ans += N * key
        break

print(ans) from collections import Counter N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split A = Counter(A) A Counter(A) Counter A for _ in range(M):
    b, c = map(int, input().split())
    A[c] += b _ range(M) range M b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c A[c] += b A[c] A c b A = sorted(A.items(), key=lambda x: x[0], reverse=True) A sorted(A.items(), key=lambda x: x[0], reverse=True) sorted A.items() A.items A items key=lambda x: x[0] key lambda x: x[0] x[0] x 0 x reverse=True reverse True ans = 0 ans 0 for key, value in A:
    if N - value >= 0:
        ans += key * value
        N -= value
    else:
        ans += N * key
        break key value A if N - value >= 0:
        ans += key * value
        N -= value
    else:
        ans += N * key
        break N - value >= 0 N - value N value 0 ans += key * value ans key * value key value N -= value N value ans += N * key ans N * key N key break print(ans) print ans A = sorted(A.items(), key=lambda x: x[0], reverse=True) sorted(A.items(), key=lambda x: x[0], reverse=True) A ans += key * value key * value ans ans = 0 0 ans A = list(map(int, input().split())) list(map(int, input().split())) A N -= value value N M = map(int, input().split()) map(int, input().split()) M b, c = map(int, input().split()) map(int, input().split()) b ans += N * key N * key ans N, M = map(int, input().split()) map(int, input().split()) N c = map(int, input().split()) map(int, input().split()) c A = Counter(A) Counter(A) A
from collections import Counter
N, M = map(int, input().split())
A = list(map(int, input().split()))

A = Counter(A)

for _ in range(M):
    b, c = map(int, input().split())
    A[c] += b

A = sorted(A.items(), key=lambda x: x[0], reverse=True)

ans = 0
for key, value in A:
    if N - value >= 0:
        ans += key * value
        N -= value
    else:
        ans += N * key
        break

print(ans)