import sys

input = sys.stdin.readline
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))[::-1]
BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1])

ans = 0
for a in A:
    if N == 0:
        break
    while len(BC) > 0 and BC[-1][1] > a and N != 0:
        b, c = BC.pop()
        i = min(N, b)
        ans += i * c
        N -= i
    if N >= 1:
        ans += a
        N -= 1
print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A = sorted(list(map(int, input().split())))[::-1] A sorted(list(map(int, input().split())))[::-1] (list(map(int, input().split()))) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ::-1 -1 list(map(int, input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1]) BC sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1]) sorted [list(map(int, input().split())) for _ in range(M)] key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x ans = 0 ans 0 for a in A:
    if N == 0:
        break
    while len(BC) > 0 and BC[-1][1] > a and N != 0:
        b, c = BC.pop()
        i = min(N, b)
        ans += i * c
        N -= i
    if N >= 1:
        ans += a
        N -= 1 a A if N == 0:
        break
     N == 0 N 0 break while len(BC) > 0 and BC[-1][1] > a and N != 0:
        b, c = BC.pop()
        i = min(N, b)
        ans += i * c
        N -= i
     len(BC) > 0 and BC[-1][1] > a and N != 0 len(BC) > 0 and BC[-1][1] > a len(BC) > 0 len(BC) len BC 0 BC[-1][1] > a BC[-1][1] [-1] BC -1 1 a N != 0 N 0 b, c = BC.pop() b BC.pop() BC.pop BC pop c i = min(N, b) i min(N, b) min N b ans += i * c ans i * c i c N -= i N i if N >= 1:
        ans += a
        N -= 1 N >= 1 N 1 ans += a ans a N -= 1 N 1 print(ans) print ans BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1]) sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1]) BC ans += i * c i * c ans b, c = BC.pop() BC.pop() b i = min(N, b) min(N, b) i ans += a a ans input = sys.stdin.readline sys.stdin.readline input N -= i i N N, M = map(int, input().split()) map(int, input().split()) N ans = 0 0 ans A = sorted(list(map(int, input().split())))[::-1] sorted(list(map(int, input().split())))[::-1] A N -= 1 1 N c = BC.pop() BC.pop() c M = map(int, input().split()) map(int, input().split()) M
import sys

input = sys.stdin.readline
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))[::-1]
BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1])

ans = 0
for a in A:
    if N == 0:
        break
    while len(BC) > 0 and BC[-1][1] > a and N != 0:
        b, c = BC.pop()
        i = min(N, b)
        ans += i * c
        N -= i
    if N >= 1:
        ans += a
        N -= 1
print(ans)
