n, m = map(int, input().split())
A = list(map(int, input().split()))

B = [[] for _ in range(m)]
for i in range(m):
    B[i] = list(map(int, input().split()))
B.sort(key=lambda x: -x[1])

_A = []
cnt = 0
for i in range(m):
    _A.extend([B[i][1]]*B[i][0])
    cnt += B[i][0]
    if cnt > n:
        break
A += _A
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 = list(map(int, input().split())) A list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split [] for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) [] B = [[] for _ in range(m)] B [[] for _ in range(m)] for i in range(m):
    B[i] = list(map(int, input().split())) i range(m) range m B[i] = list(map(int, input().split())) B[i] B i list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split B.sort(key=lambda x: -x[1]) B.sort B sort key=lambda x: -x[1] key lambda x: -x[1] -x[1] x[1] x 1 x _A = [] _A [] cnt = 0 cnt 0 for i in range(m):
    _A.extend([B[i][1]]*B[i][0])
    cnt += B[i][0]
    if cnt > n:
        break i range(m) range m _A.extend([B[i][1]]*B[i][0]) _A.extend _A extend [B[i][1]]*B[i][0] [B[i][1]] B[i][1] [i] B i 1 B[i][0] [i] B i 0 cnt += B[i][0] cnt B[i][0] [i] B i 0 if cnt > n:
        break cnt > n cnt n break A += _A A _A 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 cnt = 0 0 cnt B = [[] for _ in range(m)] [[] for _ in range(m)] B cnt += B[i][0] B[i][0] cnt n, m = map(int, input().split()) map(int, input().split()) n _A = [] [] _A A += _A _A A m = map(int, input().split()) map(int, input().split()) m A = list(map(int, input().split())) list(map(int, input().split())) A
n, m = map(int, input().split())
A = list(map(int, input().split()))

B = [[] for _ in range(m)]
for i in range(m):
    B[i] = list(map(int, input().split()))
B.sort(key=lambda x: -x[1])

_A = []
cnt = 0
for i in range(m):
    _A.extend([B[i][1]]*B[i][0])
    cnt += B[i][0]
    if cnt > n:
        break
A += _A
A.sort(reverse=True)
print(sum(A[:n]))