N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
card_dict = {}
for a in A_LIST:
    if a in card_dict:
        card_dict[a] += 1
    else:
        card_dict[a] = 1
for b, c in BC_LIST:
    if c in card_dict:
        card_dict[c] += b
    else:
        card_dict[c] = b
card_list = sorted(card_dict.items(), reverse=True, key=lambda x: x[0])
ans = 0
remaining = N
for num, cnt in card_list:
    ans += num * min(cnt, remaining)
    remaining -= min(cnt, remaining)
    if remaining == 0:
        break
print(ans) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M A_LIST = list(map(int, input().split())) A_LIST list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split BC_LIST = [] BC_LIST [] for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c]) i range(M) range M b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c BC_LIST.append([b, c]) BC_LIST.append BC_LIST append [b, c] b c card_dict = {} card_dict {} for a in A_LIST:
    if a in card_dict:
        card_dict[a] += 1
    else:
        card_dict[a] = 1 a A_LIST if a in card_dict:
        card_dict[a] += 1
    else:
        card_dict[a] = 1 a in card_dict a card_dict card_dict[a] += 1 card_dict[a] card_dict a 1 card_dict[a] = 1 card_dict[a] card_dict a 1 for b, c in BC_LIST:
    if c in card_dict:
        card_dict[c] += b
    else:
        card_dict[c] = b b c BC_LIST if c in card_dict:
        card_dict[c] += b
    else:
        card_dict[c] = b c in card_dict c card_dict card_dict[c] += b card_dict[c] card_dict c b card_dict[c] = b card_dict[c] card_dict c b card_list = sorted(card_dict.items(), reverse=True, key=lambda x: x[0]) card_list sorted(card_dict.items(), reverse=True, key=lambda x: x[0]) sorted card_dict.items() card_dict.items card_dict items reverse=True reverse True key=lambda x: x[0] key lambda x: x[0] x[0] x 0 x ans = 0 ans 0 remaining = N remaining N for num, cnt in card_list:
    ans += num * min(cnt, remaining)
    remaining -= min(cnt, remaining)
    if remaining == 0:
        break num cnt card_list ans += num * min(cnt, remaining) ans num * min(cnt, remaining) num min(cnt, remaining) min cnt remaining remaining -= min(cnt, remaining) remaining min(cnt, remaining) min cnt remaining if remaining == 0:
        break remaining == 0 remaining 0 break print(ans) print ans card_list = sorted(card_dict.items(), reverse=True, key=lambda x: x[0]) sorted(card_dict.items(), reverse=True, key=lambda x: x[0]) card_list ans = 0 0 ans N, M = map(int, input().split()) map(int, input().split()) N remaining -= min(cnt, remaining) min(cnt, remaining) remaining A_LIST = list(map(int, input().split())) list(map(int, input().split())) A_LIST M = map(int, input().split()) map(int, input().split()) M c = map(int, input().split()) map(int, input().split()) c card_dict = {} {} card_dict b, c = map(int, input().split()) map(int, input().split()) b remaining = N N remaining BC_LIST = [] [] BC_LIST ans += num * min(cnt, remaining) num * min(cnt, remaining) ans
N, M = map(int, input().split())
A_LIST = list(map(int, input().split()))
BC_LIST = []
for i in range(M):
    b, c = map(int, input().split())
    BC_LIST.append([b, c])
card_dict = {}
for a in A_LIST:
    if a in card_dict:
        card_dict[a] += 1
    else:
        card_dict[a] = 1
for b, c in BC_LIST:
    if c in card_dict:
        card_dict[c] += b
    else:
        card_dict[c] = b
card_list = sorted(card_dict.items(), reverse=True, key=lambda x: x[0])
ans = 0
remaining = N
for num, cnt in card_list:
    ans += num * min(cnt, remaining)
    remaining -= min(cnt, remaining)
    if remaining == 0:
        break
print(ans)
