N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
B = sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[1],reverse=True)
cur = 0
cnt = B[0][0]
for i in range(N):
    a = A[i]
    if cur<M and B[cur][1]>a:
        if cnt>0:
            A[i] = B[cur][1]
            cnt -= 1
        else:
            cur += 1
            if cur<M:
                cnt = B[cur][0]
                if B[cur][1]>a:
                    A[i] = B[cur][1]
                    cnt -= 1
print(sum(A)) 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 list(map(int,input().split())) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split B = sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[1],reverse=True) B sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[1],reverse=True) sorted [list(map(int,input().split())) for _ in range(M)] key=lambda x:x[1] key lambda x:x[1] x[1] x 1 x reverse=True reverse True cur = 0 cur 0 cnt = B[0][0] cnt B[0][0] [0] B 0 0 for i in range(N):
    a = A[i]
    if cur<M and B[cur][1]>a:
        if cnt>0:
            A[i] = B[cur][1]
            cnt -= 1
        else:
            cur += 1
            if cur<M:
                cnt = B[cur][0]
                if B[cur][1]>a:
                    A[i] = B[cur][1]
                    cnt -= 1 i range(N) range N a = A[i] a A[i] A i if cur<M and B[cur][1]>a:
        if cnt>0:
            A[i] = B[cur][1]
            cnt -= 1
        else:
            cur += 1
            if cur<M:
                cnt = B[cur][0]
                if B[cur][1]>a:
                    A[i] = B[cur][1]
                    cnt -= 1 cur<M and B[cur][1]>a cur<M cur M B[cur][1]>a B[cur][1] [cur] B cur 1 a if cnt>0:
            A[i] = B[cur][1]
            cnt -= 1
        else:
            cur += 1
            if cur<M:
                cnt = B[cur][0]
                if B[cur][1]>a:
                    A[i] = B[cur][1]
                    cnt -= 1 cnt>0 cnt 0 A[i] = B[cur][1] A[i] A i B[cur][1] [cur] B cur 1 cnt -= 1 cnt 1 cur += 1 cur 1 if cur<M:
                cnt = B[cur][0]
                if B[cur][1]>a:
                    A[i] = B[cur][1]
                    cnt -= 1 cur<M cur M cnt = B[cur][0] cnt B[cur][0] [cur] B cur 0 if B[cur][1]>a:
                    A[i] = B[cur][1]
                    cnt -= 1 B[cur][1]>a B[cur][1] [cur] B cur 1 a A[i] = B[cur][1] A[i] A i B[cur][1] [cur] B cur 1 cnt -= 1 cnt 1 print(sum(A)) print sum(A) sum A a = A[i] A[i] a cnt -= 1 1 cnt A = sorted(list(map(int,input().split()))) sorted(list(map(int,input().split()))) A N,M = map(int,input().split()) map(int,input().split()) N B = sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[1],reverse=True) sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[1],reverse=True) B cur += 1 1 cur M = map(int,input().split()) map(int,input().split()) M cnt -= 1 1 cnt cur = 0 0 cur cnt = B[cur][0] B[cur][0] cnt cnt = B[0][0] B[0][0] cnt
N,M = map(int,input().split())
A = sorted(list(map(int,input().split())))
B = sorted([list(map(int,input().split())) for _ in range(M)],key=lambda x:x[1],reverse=True)
cur = 0
cnt = B[0][0]
for i in range(N):
    a = A[i]
    if cur<M and B[cur][1]>a:
        if cnt>0:
            A[i] = B[cur][1]
            cnt -= 1
        else:
            cur += 1
            if cur<M:
                cnt = B[cur][0]
                if B[cur][1]>a:
                    A[i] = B[cur][1]
                    cnt -= 1
print(sum(A))