import sys
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = []

for _ in range(m):
    b += [list(map(int, input().split()))]
b = sorted(b, key=lambda x: x[1], reverse=True)

for i in range(m):
    for j in range(b[i][0]):
        if a[0] < b[i][1]:
            a.pop(0)
            a.append(b[i][1])
        else:
            print(sum(a))
            sys.exit()
print(sum(a))
            
 import sys sys 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()))) a sorted(list(map(int, input().split()))) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split b = [] b [] for _ in range(m):
    b += [list(map(int, input().split()))] _ range(m) range m b += [list(map(int, input().split()))] b [list(map(int, input().split()))] list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split b = sorted(b, key=lambda x: x[1], reverse=True) b sorted(b, key=lambda x: x[1], reverse=True) sorted b key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True for i in range(m):
    for j in range(b[i][0]):
        if a[0] < b[i][1]:
            a.pop(0)
            a.append(b[i][1])
        else:
            print(sum(a))
            sys.exit() i range(m) range m for j in range(b[i][0]):
        if a[0] < b[i][1]:
            a.pop(0)
            a.append(b[i][1])
        else:
            print(sum(a))
            sys.exit() j range(b[i][0]) range b[i][0] [i] b i 0 if a[0] < b[i][1]:
            a.pop(0)
            a.append(b[i][1])
        else:
            print(sum(a))
            sys.exit() a[0] < b[i][1] a[0] a 0 b[i][1] [i] b i 1 a.pop(0) a.pop a pop 0 a.append(b[i][1]) a.append a append b[i][1] [i] b i 1 print(sum(a)) print sum(a) sum a sys.exit() sys.exit sys exit print(sum(a)) print sum(a) sum a a = sorted(list(map(int, input().split()))) sorted(list(map(int, input().split()))) a b += [list(map(int, input().split()))] [list(map(int, input().split()))] b n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m b = [] [] b b = sorted(b, key=lambda x: x[1], reverse=True) sorted(b, key=lambda x: x[1], reverse=True) b
import sys
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
b = []

for _ in range(m):
    b += [list(map(int, input().split()))]
b = sorted(b, key=lambda x: x[1], reverse=True)

for i in range(m):
    for j in range(b[i][0]):
        if a[0] < b[i][1]:
            a.pop(0)
            a.append(b[i][1])
        else:
            print(sum(a))
            sys.exit()
print(sum(a))
            

