N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]

# Cについて大きい順にソート
BC.sort(key=lambda x: x[1], reverse=True)

temp = []
for i in range(M):
        # CiをBi個追加
    temp += [BC[i][1]] * BC[i][0]
    if len(temp) > N:
        break

A += temp
A.sort(reverse=True)

print(sum(A[:N])) N, M = list(map(int, input().split())) N list(map(int, input().split())) list 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 list(map(int, input().split())) for i in range(M) for i in range(M) i range(M) range M for i in range(M) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split BC = [list(map(int, input().split())) for i in range(M)] BC [list(map(int, input().split())) for i in range(M)] BC.sort(key=lambda x: x[1], reverse=True) BC.sort BC sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True temp = [] temp [] for i in range(M):
        # CiをBi個追加
    temp += [BC[i][1]] * BC[i][0]
    if len(temp) > N:
        break i range(M) range M temp += [BC[i][1]] * BC[i][0] temp [BC[i][1]] * BC[i][0] [BC[i][1]] BC[i][1] [i] BC i 1 BC[i][0] [i] BC i 0 if len(temp) > N:
        break len(temp) > N len(temp) len temp N break A += temp A temp A.sort(reverse=True) A.sort A sort reverse=True reverse True print(sum(A[:N])) print sum(A[:N]) sum A[:N] A :N N BC = [list(map(int, input().split())) for i in range(M)] [list(map(int, input().split())) for i in range(M)] BC A += temp temp A N, M = list(map(int, input().split())) list(map(int, input().split())) N temp = [] [] temp temp += [BC[i][1]] * BC[i][0] [BC[i][1]] * BC[i][0] temp A = list(map(int, input().split())) list(map(int, input().split())) A M = list(map(int, input().split())) list(map(int, input().split())) M
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for i in range(M)]

# Cについて大きい順にソート
BC.sort(key=lambda x: x[1], reverse=True)

temp = []
for i in range(M):
        # CiをBi個追加
    temp += [BC[i][1]] * BC[i][0]
    if len(temp) > N:
        break

A += temp
A.sort(reverse=True)

print(sum(A[:N]))
