N, M = map(int, input().split())
A_list = sorted(list(map(int, input().split())))
# C の大きさ順に
BC_list = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[1], reverse=True)
change_list_sorted = []
for m in range(M):
    b, c = BC_list[m]
    for _ in range(b):
        change_list_sorted.append(c)
    if len(change_list_sorted) > N:
        break
change_cnt = 0
for i, (change_val, a) in enumerate(zip(change_list_sorted, A_list)):
    if a <= change_val:
        A_list[i] = change_val
    else:
        break
print(sum(A_list)) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A_list = sorted(list(map(int, input().split()))) A_list sorted(list(map(int, input().split()))) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split 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_list = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[1], reverse=True) BC_list sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[1], reverse=True) 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 reverse=True reverse True change_list_sorted = [] change_list_sorted [] for m in range(M):
    b, c = BC_list[m]
    for _ in range(b):
        change_list_sorted.append(c)
    if len(change_list_sorted) > N:
        break m range(M) range M b, c = BC_list[m] b BC_list[m] BC_list m c for _ in range(b):
        change_list_sorted.append(c)
     _ range(b) range b change_list_sorted.append(c) change_list_sorted.append change_list_sorted append c if len(change_list_sorted) > N:
        break len(change_list_sorted) > N len(change_list_sorted) len change_list_sorted N break change_cnt = 0 change_cnt 0 for i, (change_val, a) in enumerate(zip(change_list_sorted, A_list)):
    if a <= change_val:
        A_list[i] = change_val
    else:
        break i (change_val, a) change_val a enumerate(zip(change_list_sorted, A_list)) enumerate zip(change_list_sorted, A_list) zip change_list_sorted A_list if a <= change_val:
        A_list[i] = change_val
    else:
        break a <= change_val a change_val A_list[i] = change_val A_list[i] A_list i change_val break print(sum(A_list)) print sum(A_list) sum A_list change_cnt = 0 0 change_cnt N, M = map(int, input().split()) map(int, input().split()) N c = BC_list[m] BC_list[m] c A_list = sorted(list(map(int, input().split()))) sorted(list(map(int, input().split()))) A_list BC_list = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[1], reverse=True) sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[1], reverse=True) BC_list M = map(int, input().split()) map(int, input().split()) M b, c = BC_list[m] BC_list[m] b change_list_sorted = [] [] change_list_sorted
N, M = map(int, input().split())
A_list = sorted(list(map(int, input().split())))
# C の大きさ順に
BC_list = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x:x[1], reverse=True)
change_list_sorted = []
for m in range(M):
    b, c = BC_list[m]
    for _ in range(b):
        change_list_sorted.append(c)
    if len(change_list_sorted) > N:
        break
change_cnt = 0
for i, (change_val, a) in enumerate(zip(change_list_sorted, A_list)):
    if a <= change_val:
        A_list[i] = change_val
    else:
        break
print(sum(A_list))