n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
bc = []
for i in range(m):
    bc.append(list(map(int, input().split())))
bc.sort(key=lambda x: x[1], reverse=True)

for i in bc:
    if a[0] < i[1]:
        for j in range(i[0]):
            if a[0] < i[1]:
                a.append(i[1])
                del a[0]
            else:
                break
    else:
        break
        
print(sum(a)) 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 a.sort() a.sort a sort bc = [] bc [] for i in range(m):
    bc.append(list(map(int, input().split()))) i range(m) range m bc.append(list(map(int, input().split()))) bc.append bc append list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split bc.sort(key=lambda x: x[1], reverse=True) bc.sort bc sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True for i in bc:
    if a[0] < i[1]:
        for j in range(i[0]):
            if a[0] < i[1]:
                a.append(i[1])
                del a[0]
            else:
                break
    else:
        break
         i bc if a[0] < i[1]:
        for j in range(i[0]):
            if a[0] < i[1]:
                a.append(i[1])
                del a[0]
            else:
                break
    else:
        break
         a[0] < i[1] a[0] a 0 i[1] i 1 for j in range(i[0]):
            if a[0] < i[1]:
                a.append(i[1])
                del a[0]
            else:
                break
     j range(i[0]) range i[0] i 0 if a[0] < i[1]:
                a.append(i[1])
                del a[0]
            else:
                break
     a[0] < i[1] a[0] a 0 i[1] i 1 a.append(i[1]) a.append a append i[1] i 1 del a[0] a[0] a 0 break break print(sum(a)) print sum(a) sum a a = list(map(int, input().split())) list(map(int, input().split())) a bc = [] [] bc n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
bc = []
for i in range(m):
    bc.append(list(map(int, input().split())))
bc.sort(key=lambda x: x[1], reverse=True)

for i in bc:
    if a[0] < i[1]:
        for j in range(i[0]):
            if a[0] < i[1]:
                a.append(i[1])
                del a[0]
            else:
                break
    else:
        break
        
print(sum(a))
