import numpy as np
 
n, m = map(int, input().split())
 
cards = list(map(int, input().split()))
cards = np.array(cards, np.int64)
cards.sort()

bc = [list(map(int, input().split())) for _ in range(m)]
bc = np.array(bc, np.int64)

B = bc[:,0]
C = bc[:,1]
 
#並び替えた配列のidxをnparrayで取得
idx = C.argsort()
B = B[idx][::-1]
C = C[idx][::-1]
 
p = 0
for b,c in zip(B,C):
    cards[p:p+b] = np.maximum(cards[p:p+b], c)
    p += b

print(sum(cards)) import numpy as np numpy n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m cards = list(map(int, input().split())) cards list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split cards = np.array(cards, np.int64) cards np.array(cards, np.int64) np.array np array cards np.int64 np int64 cards.sort() cards.sort cards sort 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 bc = [list(map(int, input().split())) for _ in range(m)] bc [list(map(int, input().split())) for _ in range(m)] bc = np.array(bc, np.int64) bc np.array(bc, np.int64) np.array np array bc np.int64 np int64 B = bc[:,0] B bc[:,0] bc : C = bc[:,1] C bc[:,1] bc : idx = C.argsort() idx C.argsort() C.argsort C argsort B = B[idx][::-1] B B[idx][::-1] [idx] B idx ::-1 -1 C = C[idx][::-1] C C[idx][::-1] [idx] C idx ::-1 -1 p = 0 p 0 for b,c in zip(B,C):
    cards[p:p+b] = np.maximum(cards[p:p+b], c)
    p += b b c zip(B,C) zip B C cards[p:p+b] = np.maximum(cards[p:p+b], c) cards[p:p+b] cards p:p+b p p+b p b np.maximum(cards[p:p+b], c) np.maximum np maximum cards[p:p+b] cards p:p+b p p+b p b c p += b p b print(sum(cards)) print sum(cards) sum cards bc = [list(map(int, input().split())) for _ in range(m)] [list(map(int, input().split())) for _ in range(m)] bc bc = np.array(bc, np.int64) np.array(bc, np.int64) bc n, m = map(int, input().split()) map(int, input().split()) n cards = list(map(int, input().split())) list(map(int, input().split())) cards B = bc[:,0] bc[:,0] B cards = np.array(cards, np.int64) np.array(cards, np.int64) cards B = B[idx][::-1] B[idx][::-1] B C = C[idx][::-1] C[idx][::-1] C m = map(int, input().split()) map(int, input().split()) m C = bc[:,1] bc[:,1] C idx = C.argsort() C.argsort() idx p += b b p p = 0 0 p
import numpy as np
 
n, m = map(int, input().split())
 
cards = list(map(int, input().split()))
cards = np.array(cards, np.int64)
cards.sort()

bc = [list(map(int, input().split())) for _ in range(m)]
bc = np.array(bc, np.int64)

B = bc[:,0]
C = bc[:,1]
 
#並び替えた配列のidxをnparrayで取得
idx = C.argsort()
B = B[idx][::-1]
C = C[idx][::-1]
 
p = 0
for b,c in zip(B,C):
    cards[p:p+b] = np.maximum(cards[p:p+b], c)
    p += b

print(sum(cards))