from collections import deque

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

BC_dict={}
for m in range(M):
    b,c = list(map(int,input().split()))
    if c in BC_dict.keys():
        BC_dict[c]+=b  
    else:    
        BC_dict[c]=b  
    
C = list(BC_dict.keys())

A.sort()
C.sort(reverse=True)

C=deque(C)

check = C.popleft()

for a_idx,a in enumerate(A):
    if a >= check:
        break
    
    A[a_idx] = check
    BC_dict[check] -= 1
    
    if BC_dict[check] == 0:
        if len(C) == 0:
            break
        else:
            check = C.popleft()
        
print(sum(A)) from collections import deque N,M = list(map(int,input().split())) N list(map(int,input().split())) list 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 BC_dict={} BC_dict {} for m in range(M):
    b,c = list(map(int,input().split()))
    if c in BC_dict.keys():
        BC_dict[c]+=b  
    else:    
        BC_dict[c]=b  
     m range(M) range M b,c = list(map(int,input().split())) b list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split c if c in BC_dict.keys():
        BC_dict[c]+=b  
    else:    
        BC_dict[c]=b  
     c in BC_dict.keys() c BC_dict.keys() BC_dict.keys BC_dict keys BC_dict[c]+=b BC_dict[c] BC_dict c b BC_dict[c]=b BC_dict[c] BC_dict c b C = list(BC_dict.keys()) C list(BC_dict.keys()) list BC_dict.keys() BC_dict.keys BC_dict keys A.sort() A.sort A sort C.sort(reverse=True) C.sort C sort reverse=True reverse True C=deque(C) C deque(C) deque C check = C.popleft() check C.popleft() C.popleft C popleft for a_idx,a in enumerate(A):
    if a >= check:
        break
    
    A[a_idx] = check
    BC_dict[check] -= 1
    
    if BC_dict[check] == 0:
        if len(C) == 0:
            break
        else:
            check = C.popleft()
         a_idx a enumerate(A) enumerate A if a >= check:
        break
    
     a >= check a check break A[a_idx] = check A[a_idx] A a_idx check BC_dict[check] -= 1 BC_dict[check] BC_dict check 1 if BC_dict[check] == 0:
        if len(C) == 0:
            break
        else:
            check = C.popleft()
         BC_dict[check] == 0 BC_dict[check] BC_dict check 0 if len(C) == 0:
            break
        else:
            check = C.popleft()
         len(C) == 0 len(C) len C 0 break check = C.popleft() check C.popleft() C.popleft C popleft print(sum(A)) print sum(A) sum A b,c = list(map(int,input().split())) list(map(int,input().split())) b BC_dict={} {} BC_dict A = list(map(int,input().split())) list(map(int,input().split())) A c = list(map(int,input().split())) list(map(int,input().split())) c C=deque(C) deque(C) C N,M = list(map(int,input().split())) list(map(int,input().split())) N check = C.popleft() C.popleft() check M = list(map(int,input().split())) list(map(int,input().split())) M C = list(BC_dict.keys()) list(BC_dict.keys()) C check = C.popleft() C.popleft() check
from collections import deque

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

BC_dict={}
for m in range(M):
    b,c = list(map(int,input().split()))
    if c in BC_dict.keys():
        BC_dict[c]+=b  
    else:    
        BC_dict[c]=b  
    
C = list(BC_dict.keys())

A.sort()
C.sort(reverse=True)

C=deque(C)

check = C.popleft()

for a_idx,a in enumerate(A):
    if a >= check:
        break
    
    A[a_idx] = check
    BC_dict[check] -= 1
    
    if BC_dict[check] == 0:
        if len(C) == 0:
            break
        else:
            check = C.popleft()
        
print(sum(A))