n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
list = [list(map(int, input().split())) for x in range(m)]
list.sort(key=lambda x: x[1], reverse=True) # １番の要素で降順ソート

app_count = 0
for i in list:
    a += [i[1]]*i[0]
    app_count += i[0]
    if app_count>n:
        break

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 a.sort() a.sort a sort list(map(int, input().split())) for x in range(m) for x in range(m) x range(m) range m for x in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split list = [list(map(int, input().split())) for x in range(m)] list [list(map(int, input().split())) for x in range(m)] list.sort(key=lambda x: x[1], reverse=True) list.sort list sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True app_count = 0 app_count 0 for i in list:
    a += [i[1]]*i[0]
    app_count += i[0]
    if app_count>n:
        break i list a += [i[1]]*i[0] a [i[1]]*i[0] [i[1]] i[1] i 1 i[0] i 0 app_count += i[0] app_count i[0] i 0 if app_count>n:
        break app_count>n app_count n break 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 = list(map(int, input().split())) list(map(int, input().split())) m app_count += i[0] i[0] app_count list = [list(map(int, input().split())) for x in range(m)] [list(map(int, input().split())) for x in range(m)] list a += [i[1]]*i[0] [i[1]]*i[0] a a = list(map(int, input().split())) list(map(int, input().split())) a n, m = list(map(int, input().split())) list(map(int, input().split())) n app_count = 0 0 app_count
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
list = [list(map(int, input().split())) for x in range(m)]
list.sort(key=lambda x: x[1], reverse=True) # １番の要素で降順ソート

app_count = 0
for i in list:
    a += [i[1]]*i[0]
    app_count += i[0]
    if app_count>n:
        break

a.sort(reverse=True)

print(sum(a[:n]))
