N, M = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

card = [0] * M
for i in range(M):
    b, c = map(int, input().split())
    card[i] = (c, b)

card.sort(reverse=True)

arr = []
l = 0
#変更できるカード配列を作る
for i in range(M):
    if l+card[i][1] > 10**5:
        add = 10**5-l
        for j in range(add):
            arr.append(card[i][0])
        break
    else:
        for j in range(card[i][1]):
            arr.append(card[i][0])
        l += card[i][1]

a = a+arr
a.sort(reverse=True)
print(sum(a[:N])) 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())), reverse=True) a sorted(list(map(int, input().split())), reverse=True) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split reverse=True reverse True card = [0] * M card [0] * M [0] 0 M for i in range(M):
    b, c = map(int, input().split())
    card[i] = (c, b) i range(M) range M b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c card[i] = (c, b) card[i] card i (c, b) c b card.sort(reverse=True) card.sort card sort reverse=True reverse True arr = [] arr [] l = 0 l 0 for i in range(M):
    if l+card[i][1] > 10**5:
        add = 10**5-l
        for j in range(add):
            arr.append(card[i][0])
        break
    else:
        for j in range(card[i][1]):
            arr.append(card[i][0])
        l += card[i][1] i range(M) range M if l+card[i][1] > 10**5:
        add = 10**5-l
        for j in range(add):
            arr.append(card[i][0])
        break
    else:
        for j in range(card[i][1]):
            arr.append(card[i][0])
        l += card[i][1] l+card[i][1] > 10**5 l+card[i][1] l card[i][1] [i] card i 1 10**5 10 5 add = 10**5-l add 10**5-l 10**5 10 5 l for j in range(add):
            arr.append(card[i][0])
         j range(add) range add arr.append(card[i][0]) arr.append arr append card[i][0] [i] card i 0 break for j in range(card[i][1]):
            arr.append(card[i][0])
         j range(card[i][1]) range card[i][1] [i] card i 1 arr.append(card[i][0]) arr.append arr append card[i][0] [i] card i 0 l += card[i][1] l card[i][1] [i] card i 1 a = a+arr a a+arr a arr 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 M = map(int, input().split()) map(int, input().split()) M l = 0 0 l arr = [] [] arr a = sorted(list(map(int, input().split())), reverse=True) sorted(list(map(int, input().split())), reverse=True) a card = [0] * M [0] * M card N, M = map(int, input().split()) map(int, input().split()) N l += card[i][1] card[i][1] l b, c = map(int, input().split()) map(int, input().split()) b add = 10**5-l 10**5-l add c = map(int, input().split()) map(int, input().split()) c a = a+arr a+arr a
N, M = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

card = [0] * M
for i in range(M):
    b, c = map(int, input().split())
    card[i] = (c, b)

card.sort(reverse=True)

arr = []
l = 0
#変更できるカード配列を作る
for i in range(M):
    if l+card[i][1] > 10**5:
        add = 10**5-l
        for j in range(add):
            arr.append(card[i][0])
        break
    else:
        for j in range(card[i][1]):
            arr.append(card[i][0])
        l += card[i][1]

a = a+arr
a.sort(reverse=True)
print(sum(a[:N]))