N, M = map(int, input().split())
A = list(map(int, input().split()))

dic = {}
for i in range(N):
    tmp = A[i]
    if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1

for _ in range(M):
    B, C = map(int, input().split())
    if C in dic:
        dic[C] += B
    else:
        dic[C] = B

dic = sorted(dic.items(), reverse=True)

ans, cnt = 0, 0
i = 0
while True:
    k, v = dic[i]
    cnt += v
    if cnt < N:
        ans += k*v
    elif cnt == N:
        ans += k*v
        break
    else:
        ans += k*(v - (cnt-N))
        break
    i += 1

print(ans) 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 dic = {} dic {} for i in range(N):
    tmp = A[i]
    if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1 i range(N) range N tmp = A[i] tmp A[i] A i if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1 tmp in dic tmp dic dic[tmp] += 1 dic[tmp] dic tmp 1 dic[tmp] = 1 dic[tmp] dic tmp 1 for _ in range(M):
    B, C = map(int, input().split())
    if C in dic:
        dic[C] += B
    else:
        dic[C] = B _ range(M) range M B, C = map(int, input().split()) B map(int, input().split()) map int input().split() ().split () input split C if C in dic:
        dic[C] += B
    else:
        dic[C] = B C in dic C dic dic[C] += B dic[C] dic C B dic[C] = B dic[C] dic C B dic = sorted(dic.items(), reverse=True) dic sorted(dic.items(), reverse=True) sorted dic.items() dic.items dic items reverse=True reverse True ans, cnt = 0, 0 ans 0 cnt 0 i = 0 i 0 while True:
    k, v = dic[i]
    cnt += v
    if cnt < N:
        ans += k*v
    elif cnt == N:
        ans += k*v
        break
    else:
        ans += k*(v - (cnt-N))
        break
    i += 1 True k, v = dic[i] k dic[i] dic i v cnt += v cnt v if cnt < N:
        ans += k*v
    elif cnt == N:
        ans += k*v
        break
    else:
        ans += k*(v - (cnt-N))
        break
     cnt < N cnt N ans += k*v ans k*v k v elif cnt == N:
        ans += k*v
        break
     cnt == N cnt N ans += k*v ans k*v k v break ans += k*(v - (cnt-N)) ans k*(v - (cnt-N)) k v - (cnt-N) v cnt-N cnt N break i += 1 i 1 print(ans) print ans dic = sorted(dic.items(), reverse=True) sorted(dic.items(), reverse=True) dic A = list(map(int, input().split())) list(map(int, input().split())) A v = dic[i] dic[i] v i = 0 0 i ans += k*v k*v ans M = map(int, input().split()) map(int, input().split()) M tmp = A[i] A[i] tmp k, v = dic[i] dic[i] k dic = {} {} dic cnt += v v cnt ans += k*v k*v ans B, C = map(int, input().split()) map(int, input().split()) B cnt = 0, 0 0 cnt C = map(int, input().split()) map(int, input().split()) C N, M = map(int, input().split()) map(int, input().split()) N i += 1 1 i ans, cnt = 0, 0 0 ans ans += k*(v - (cnt-N)) k*(v - (cnt-N)) ans
N, M = map(int, input().split())
A = list(map(int, input().split()))

dic = {}
for i in range(N):
    tmp = A[i]
    if tmp in dic:
        dic[tmp] += 1
    else:
        dic[tmp] = 1

for _ in range(M):
    B, C = map(int, input().split())
    if C in dic:
        dic[C] += B
    else:
        dic[C] = B

dic = sorted(dic.items(), reverse=True)

ans, cnt = 0, 0
i = 0
while True:
    k, v = dic[i]
    cnt += v
    if cnt < N:
        ans += k*v
    elif cnt == N:
        ans += k*v
        break
    else:
        ans += k*(v - (cnt-N))
        break
    i += 1

print(ans)