N, M = map(int, input().split())
A = list(map(int, input().split()))
CB = []

for _ in range(M):
    b, c = map(int, input().split())
    CB.append((c, b))

CB.sort(reverse=True)
A.sort()
ans = 0
now = 0
count = 0
for i in range(len(A)):
    if A[i] >= CB[now][0]:
        ans += A[i]
    else:
        ans += CB[now][0]
        count += 1
    
    if count == CB[now][1]: # 枚数を超えたら
        count = 0
        now += 1
    if now >= len(CB):
        stoped_idx = i
        ans += sum(A[stoped_idx + 1:])
        break
print(ans) 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 CB = [] CB [] for _ in range(M):
    b, c = map(int, input().split())
    CB.append((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 CB.append((c, b)) CB.append CB append (c, b) c b CB.sort(reverse=True) CB.sort CB sort reverse=True reverse True A.sort() A.sort A sort ans = 0 ans 0 now = 0 now 0 count = 0 count 0 for i in range(len(A)):
    if A[i] >= CB[now][0]:
        ans += A[i]
    else:
        ans += CB[now][0]
        count += 1
    
    if count == CB[now][1]: # 枚数を超えたら
        count = 0
        now += 1
    if now >= len(CB):
        stoped_idx = i
        ans += sum(A[stoped_idx + 1:])
        break i range(len(A)) range len(A) len A if A[i] >= CB[now][0]:
        ans += A[i]
    else:
        ans += CB[now][0]
        count += 1
    
     A[i] >= CB[now][0] A[i] A i CB[now][0] [now] CB now 0 ans += A[i] ans A[i] A i ans += CB[now][0] ans CB[now][0] [now] CB now 0 count += 1 count 1 if count == CB[now][1]: # 枚数を超えたら
        count = 0
        now += 1
     count == CB[now][1] count CB[now][1] [now] CB now 1 count = 0 count 0 now += 1 now 1 if now >= len(CB):
        stoped_idx = i
        ans += sum(A[stoped_idx + 1:])
        break now >= len(CB) now len(CB) len CB stoped_idx = i stoped_idx i ans += sum(A[stoped_idx + 1:]) ans sum(A[stoped_idx + 1:]) sum A[stoped_idx + 1:] A stoped_idx + 1: stoped_idx + 1 stoped_idx 1 break print(ans) print ans c = map(int, input().split()) map(int, input().split()) c count = 0 0 count b, c = map(int, input().split()) map(int, input().split()) b ans += A[i] A[i] ans count += 1 1 count A = list(map(int, input().split())) list(map(int, input().split())) A N, M = map(int, input().split()) map(int, input().split()) N CB = [] [] CB stoped_idx = i i stoped_idx ans = 0 0 ans now += 1 1 now M = map(int, input().split()) map(int, input().split()) M ans += CB[now][0] CB[now][0] ans now = 0 0 now ans += sum(A[stoped_idx + 1:]) sum(A[stoped_idx + 1:]) ans count = 0 0 count
N, M = map(int, input().split())
A = list(map(int, input().split()))
CB = []

for _ in range(M):
    b, c = map(int, input().split())
    CB.append((c, b))

CB.sort(reverse=True)
A.sort()
ans = 0
now = 0
count = 0
for i in range(len(A)):
    if A[i] >= CB[now][0]:
        ans += A[i]
    else:
        ans += CB[now][0]
        count += 1
    
    if count == CB[now][1]: # 枚数を超えたら
        count = 0
        now += 1
    if now >= len(CB):
        stoped_idx = i
        ans += sum(A[stoped_idx + 1:])
        break
print(ans)