# 初期入力
#import numpy as np
import sys
input = sys.stdin.readline
N,M = (int(i) for i in input().split())
A = list(map(int, input().split()))
take =[[-1] for i in range(M)]
for x in range(M):
    B,C = (int(i) for i in input().split())
    take[x] =B,C

#
A.sort()
take.sort(key=lambda x: x[1], reverse=True)
take =[(0,0)] +take
ind =[0]*(M+1)
for i in range(1,M+1): #初項に「０」足したから「M]まで
    ind[i] =ind[i-1] +take[i][0]
    if ind[i-1] >=N:
        break
    elif A[ind[i-1]] >=take[i][1]:
        break
    elif ind[i] <N and A[ind[i]] <take[i][1]: #全て一括で置き換える
        A[ind[i-1] :ind[i]] =[take[i][1] ] *(take[i][0]) 
    else:
        for j in range(ind[i-1],ind[i]): #最後は1つずつ確認しながら置き換える
            if N <= j:
                break
            if A[j] <take[i][1]:
                A[j] =take[i][1]
            else:
                break
print(sum(A)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i N,M = (int(i) for i in input().split()) N (int(i) for i in 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 [-1] for i in range(M) for i in range(M) i range(M) range M for i in range(M) [-1] -1 take =[[-1] for i in range(M)] take [[-1] for i in range(M)] for x in range(M):
    B,C = (int(i) for i in input().split())
    take[x] =B,C

# x range(M) range M int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i B,C = (int(i) for i in input().split()) B (int(i) for i in input().split()) C take[x] =B,C take[x] take x take[x] =B,C B C A.sort() A.sort A sort take.sort(key=lambda x: x[1], reverse=True) take.sort take sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True take =[(0,0)] +take take [(0,0)] +take [(0,0)] (0,0) 0 0 take ind =[0]*(M+1) ind [0]*(M+1) [0] 0 M+1 M 1 for i in range(1,M+1): #初項に「０」足したから「M]まで
    ind[i] =ind[i-1] +take[i][0]
    if ind[i-1] >=N:
        break
    elif A[ind[i-1]] >=take[i][1]:
        break
    elif ind[i] <N and A[ind[i]] <take[i][1]: #全て一括で置き換える
        A[ind[i-1] :ind[i]] =[take[i][1] ] *(take[i][0]) 
    else:
        for j in range(ind[i-1],ind[i]): #最後は1つずつ確認しながら置き換える
            if N <= j:
                break
            if A[j] <take[i][1]:
                A[j] =take[i][1]
            else:
                break i range(1,M+1) range 1 M+1 M 1 ind[i] =ind[i-1] +take[i][0] ind[i] ind i ind[i-1] +take[i][0] ind[i-1] ind i-1 i 1 take[i][0] [i] take i 0 if ind[i-1] >=N:
        break
    elif A[ind[i-1]] >=take[i][1]:
        break
    elif ind[i] <N and A[ind[i]] <take[i][1]: #全て一括で置き換える
        A[ind[i-1] :ind[i]] =[take[i][1] ] *(take[i][0]) 
    else:
        for j in range(ind[i-1],ind[i]): #最後は1つずつ確認しながら置き換える
            if N <= j:
                break
            if A[j] <take[i][1]:
                A[j] =take[i][1]
            else:
                break ind[i-1] >=N ind[i-1] ind i-1 i 1 N break elif A[ind[i-1]] >=take[i][1]:
        break
     A[ind[i-1]] >=take[i][1] A[ind[i-1]] A ind[i-1] ind i-1 i 1 take[i][1] [i] take i 1 break elif ind[i] <N and A[ind[i]] <take[i][1]: #全て一括で置き換える
        A[ind[i-1] :ind[i]] =[take[i][1] ] *(take[i][0]) 
     ind[i] <N and A[ind[i]] <take[i][1] ind[i] <N ind[i] ind i N A[ind[i]] <take[i][1] A[ind[i]] A ind[i] ind i take[i][1] [i] take i 1 A[ind[i-1] :ind[i]] =[take[i][1] ] *(take[i][0]) A[ind[i-1] :ind[i]] A ind[i-1] :ind[i] ind[i-1] ind i-1 i 1 ind[i] ind i [take[i][1] ] *(take[i][0]) [take[i][1] ] take[i][1] [i] take i 1 take[i][0] [i] take i 0 for j in range(ind[i-1],ind[i]): #最後は1つずつ確認しながら置き換える
            if N <= j:
                break
            if A[j] <take[i][1]:
                A[j] =take[i][1]
            else:
                break j range(ind[i-1],ind[i]) range ind[i-1] ind i-1 i 1 ind[i] ind i if N <= j:
                break
             N <= j N j break if A[j] <take[i][1]:
                A[j] =take[i][1]
            else:
                break A[j] <take[i][1] A[j] A j take[i][1] [i] take i 1 A[j] =take[i][1] A[j] A j take[i][1] [i] take i 1 break print(sum(A)) print sum(A) sum A M = (int(i) for i in input().split()) (int(i) for i in input().split()) M take =[[-1] for i in range(M)] [[-1] for i in range(M)] take N,M = (int(i) for i in input().split()) (int(i) for i in input().split()) N B,C = (int(i) for i in input().split()) (int(i) for i in input().split()) B input = sys.stdin.readline sys.stdin.readline input take =[(0,0)] +take [(0,0)] +take take A = list(map(int, input().split())) list(map(int, input().split())) A C = (int(i) for i in input().split()) (int(i) for i in input().split()) C ind =[0]*(M+1) [0]*(M+1) ind
# 初期入力
#import numpy as np
import sys
input = sys.stdin.readline
N,M = (int(i) for i in input().split())
A = list(map(int, input().split()))
take =[[-1] for i in range(M)]
for x in range(M):
    B,C = (int(i) for i in input().split())
    take[x] =B,C

#
A.sort()
take.sort(key=lambda x: x[1], reverse=True)
take =[(0,0)] +take
ind =[0]*(M+1)
for i in range(1,M+1): #初項に「０」足したから「M]まで
    ind[i] =ind[i-1] +take[i][0]
    if ind[i-1] >=N:
        break
    elif A[ind[i-1]] >=take[i][1]:
        break
    elif ind[i] <N and A[ind[i]] <take[i][1]: #全て一括で置き換える
        A[ind[i-1] :ind[i]] =[take[i][1] ] *(take[i][0]) 
    else:
        for j in range(ind[i-1],ind[i]): #最後は1つずつ確認しながら置き換える
            if N <= j:
                break
            if A[j] <take[i][1]:
                A[j] =take[i][1]
            else:
                break
print(sum(A))