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

CB = []
for i in range(M):
    b, c = map(int, input().split())
    CB.append([c, b])
CB.sort(reverse=True)
CBCB = [CB[0]]
for i in range(1, M):
    if CB[i][0]==CB[i-1][0]:
        CBCB[-1][1]+= CB[i][1]
    else:
        CBCB.append(CB[i])

ind = 0
ans=0
for l in CBCB:
    if A[ind]>l[0]: # 打ち切り
        break
    elif A[min(ind+l[1]-1, N-1)]<l[0]: #すべて置き換え
        if ind+l[1]>N-1:
            ans+=l[0]*(N-ind)
            ind = N
            break
        else:
            ans+=l[0]*l[1]
            ind+=l[1]
    else:
        sm = ind-1
        la = min(ind + l[1] -1 , N-1)
        while sm+1<la:
            md = (sm+la)//2
            if A[md]>=l[0]:
                la = md
            else:
                sm = md
        ans += l[0]*(sm-ind+1)
        ind = sm+1
        break
        
for i in range(ind, N):
    ans+=A[i]
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 A.sort() A.sort A sort CB = [] CB [] for i in range(M):
    b, c = map(int, input().split())
    CB.append([c, b]) i range(M) range M b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c CB.append([c, b]) CB.append CB append [c, b] c b CB.sort(reverse=True) CB.sort CB sort reverse=True reverse True CBCB = [CB[0]] CBCB [CB[0]] CB[0] CB 0 for i in range(1, M):
    if CB[i][0]==CB[i-1][0]:
        CBCB[-1][1]+= CB[i][1]
    else:
        CBCB.append(CB[i]) i range(1, M) range 1 M if CB[i][0]==CB[i-1][0]:
        CBCB[-1][1]+= CB[i][1]
    else:
        CBCB.append(CB[i]) CB[i][0]==CB[i-1][0] CB[i][0] [i] CB i 0 CB[i-1][0] [i-1] CB i-1 i 1 0 CBCB[-1][1]+= CB[i][1] CBCB[-1][1] [-1] CBCB -1 1 CB[i][1] [i] CB i 1 CBCB.append(CB[i]) CBCB.append CBCB append CB[i] CB i ind = 0 ind 0 ans=0 ans 0 for l in CBCB:
    if A[ind]>l[0]: # 打ち切り
        break
    elif A[min(ind+l[1]-1, N-1)]<l[0]: #すべて置き換え
        if ind+l[1]>N-1:
            ans+=l[0]*(N-ind)
            ind = N
            break
        else:
            ans+=l[0]*l[1]
            ind+=l[1]
    else:
        sm = ind-1
        la = min(ind + l[1] -1 , N-1)
        while sm+1<la:
            md = (sm+la)//2
            if A[md]>=l[0]:
                la = md
            else:
                sm = md
        ans += l[0]*(sm-ind+1)
        ind = sm+1
        break
         l CBCB if A[ind]>l[0]: # 打ち切り
        break
    elif A[min(ind+l[1]-1, N-1)]<l[0]: #すべて置き換え
        if ind+l[1]>N-1:
            ans+=l[0]*(N-ind)
            ind = N
            break
        else:
            ans+=l[0]*l[1]
            ind+=l[1]
    else:
        sm = ind-1
        la = min(ind + l[1] -1 , N-1)
        while sm+1<la:
            md = (sm+la)//2
            if A[md]>=l[0]:
                la = md
            else:
                sm = md
        ans += l[0]*(sm-ind+1)
        ind = sm+1
        break
         A[ind]>l[0] A[ind] A ind l[0] l 0 break elif A[min(ind+l[1]-1, N-1)]<l[0]: #すべて置き換え
        if ind+l[1]>N-1:
            ans+=l[0]*(N-ind)
            ind = N
            break
        else:
            ans+=l[0]*l[1]
            ind+=l[1]
     A[min(ind+l[1]-1, N-1)]<l[0] A[min(ind+l[1]-1, N-1)] A min(ind+l[1]-1, N-1) min ind+l[1]-1 ind+l[1] ind l[1] l 1 1 N-1 N 1 l[0] l 0 if ind+l[1]>N-1:
            ans+=l[0]*(N-ind)
            ind = N
            break
        else:
            ans+=l[0]*l[1]
            ind+=l[1]
     ind+l[1]>N-1 ind+l[1] ind l[1] l 1 N-1 N 1 ans+=l[0]*(N-ind) ans l[0]*(N-ind) l[0] l 0 N-ind N ind ind = N ind N break ans+=l[0]*l[1] ans l[0]*l[1] l[0] l 0 l[1] l 1 ind+=l[1] ind l[1] l 1 sm = ind-1 sm ind-1 ind 1 la = min(ind + l[1] -1 , N-1) la min(ind + l[1] -1 , N-1) min ind + l[1] -1 ind + l[1] ind l[1] l 1 1 N-1 N 1 while sm+1<la:
            md = (sm+la)//2
            if A[md]>=l[0]:
                la = md
            else:
                sm = md
         sm+1<la sm+1 sm 1 la md = (sm+la)//2 md (sm+la)//2 sm+la sm la 2 if A[md]>=l[0]:
                la = md
            else:
                sm = md
         A[md]>=l[0] A[md] A md l[0] l 0 la = md la md sm = md sm md ans += l[0]*(sm-ind+1) ans l[0]*(sm-ind+1) l[0] l 0 sm-ind+1 sm-ind sm ind 1 ind = sm+1 ind sm+1 sm 1 break for i in range(ind, N):
    ans+=A[i] i range(ind, N) range ind N ans+=A[i] ans A[i] A i print(ans) print ans ans+=l[0]*l[1] l[0]*l[1] ans sm = md md sm A = list(map(int, input().split())) list(map(int, input().split())) A c = map(int, input().split()) map(int, input().split()) c ans=0 0 ans ind = 0 0 ind ans += l[0]*(sm-ind+1) l[0]*(sm-ind+1) ans md = (sm+la)//2 (sm+la)//2 md ans+=A[i] A[i] ans ind = N N ind ans+=l[0]*(N-ind) l[0]*(N-ind) ans CBCB = [CB[0]] [CB[0]] CBCB sm = ind-1 ind-1 sm CB = [] [] CB M = map(int, input().split()) map(int, input().split()) M la = md md la la = min(ind + l[1] -1 , N-1) min(ind + l[1] -1 , N-1) la ind = sm+1 sm+1 ind N, M = map(int, input().split()) map(int, input().split()) N b, c = map(int, input().split()) map(int, input().split()) b ind+=l[1] l[1] ind
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

CB = []
for i in range(M):
    b, c = map(int, input().split())
    CB.append([c, b])
CB.sort(reverse=True)
CBCB = [CB[0]]
for i in range(1, M):
    if CB[i][0]==CB[i-1][0]:
        CBCB[-1][1]+= CB[i][1]
    else:
        CBCB.append(CB[i])

ind = 0
ans=0
for l in CBCB:
    if A[ind]>l[0]: # 打ち切り
        break
    elif A[min(ind+l[1]-1, N-1)]<l[0]: #すべて置き換え
        if ind+l[1]>N-1:
            ans+=l[0]*(N-ind)
            ind = N
            break
        else:
            ans+=l[0]*l[1]
            ind+=l[1]
    else:
        sm = ind-1
        la = min(ind + l[1] -1 , N-1)
        while sm+1<la:
            md = (sm+la)//2
            if A[md]>=l[0]:
                la = md
            else:
                sm = md
        ans += l[0]*(sm-ind+1)
        ind = sm+1
        break
        
for i in range(ind, N):
    ans+=A[i]
print(ans)