N, M = map(int, input().split())
As = list(map(int, input().split()))
BCs = [list(map(int, input().split())) for _ in range(M)]

BCs = sorted(BCs,reverse = True, key = lambda x: x[1])
As = sorted(As, key = lambda x:x)

#%%
A_ind = 0

for BC in BCs:
    count = BC[0]
    value = BC[1]
    
    for i in range(count):
        if As[A_ind] < value:
            As[A_ind] = value
            A_ind += 1
            if A_ind >= len(As):
                break
        else:
            break
        
    else:
        continue
    break

print(sum(As)) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M As = list(map(int, input().split())) As 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 BCs = [list(map(int, input().split())) for _ in range(M)] BCs [list(map(int, input().split())) for _ in range(M)] BCs = sorted(BCs,reverse = True, key = lambda x: x[1]) BCs sorted(BCs,reverse = True, key = lambda x: x[1]) sorted BCs reverse = True reverse True key = lambda x: x[1] key lambda x: x[1] x[1] x 1 x As = sorted(As, key = lambda x:x) As sorted(As, key = lambda x:x) sorted As key = lambda x:x key lambda x:x x x A_ind = 0 A_ind 0 for BC in BCs:
    count = BC[0]
    value = BC[1]
    
    for i in range(count):
        if As[A_ind] < value:
            As[A_ind] = value
            A_ind += 1
            if A_ind >= len(As):
                break
        else:
            break
        
    else:
        continue
    break BC BCs count = BC[0] count BC[0] BC 0 value = BC[1] value BC[1] BC 1 for i in range(count):
        if As[A_ind] < value:
            As[A_ind] = value
            A_ind += 1
            if A_ind >= len(As):
                break
        else:
            break
        
    else:
        continue
     i range(count) range count if As[A_ind] < value:
            As[A_ind] = value
            A_ind += 1
            if A_ind >= len(As):
                break
        else:
            break
        
     As[A_ind] < value As[A_ind] As A_ind value As[A_ind] = value As[A_ind] As A_ind value A_ind += 1 A_ind 1 if A_ind >= len(As):
                break
         A_ind >= len(As) A_ind len(As) len As break break continue break print(sum(As)) print sum(As) sum As N, M = map(int, input().split()) map(int, input().split()) N BCs = sorted(BCs,reverse = True, key = lambda x: x[1]) sorted(BCs,reverse = True, key = lambda x: x[1]) BCs M = map(int, input().split()) map(int, input().split()) M A_ind += 1 1 A_ind As = sorted(As, key = lambda x:x) sorted(As, key = lambda x:x) As A_ind = 0 0 A_ind As = list(map(int, input().split())) list(map(int, input().split())) As count = BC[0] BC[0] count BCs = [list(map(int, input().split())) for _ in range(M)] [list(map(int, input().split())) for _ in range(M)] BCs value = BC[1] BC[1] value
N, M = map(int, input().split())
As = list(map(int, input().split()))
BCs = [list(map(int, input().split())) for _ in range(M)]

BCs = sorted(BCs,reverse = True, key = lambda x: x[1])
As = sorted(As, key = lambda x:x)

#%%
A_ind = 0

for BC in BCs:
    count = BC[0]
    value = BC[1]
    
    for i in range(count):
        if As[A_ind] < value:
            As[A_ind] = value
            A_ind += 1
            if A_ind >= len(As):
                break
        else:
            break
        
    else:
        continue
    break

print(sum(As))