from heapq import heappush, heappop



# input

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

A = [0]*N

B = [0]*M

C = [0]*M



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

A.sort()

for i in range(M):

    B[i],C[i] = list(map(int,input().split()))





def solve():



    pairs = list(zip(C, B))

    sortedpairs = sorted(pairs, key=lambda x: x[0])

    for i in range(M):

        B[i]=sortedpairs[i][1]

        C[i]=sortedpairs[i][0]



    ansA=[0]*N

    for j in range(N):

        ansA[j] = A[j]



    p = int(0)

    j = int(0)

    while  j<N and M>=1+p :

        jd = int(0)

        if ansA[j] >= C[M - 1 - p]:

            break

        while  B[M-1-p]-jd>0 :

            if j==N : break

            if ansA[j]>=C[M-1-p] :

                break

            else:

                ansA[j]=C[M-1-p]

            jd +=1

            j +=1



        p +=1



    ans = int(0)

    for j in range(N):

        ans += ansA[j]



    print(ans)



solve()



import heapq

import sys

def I(): return int(sys.stdin.readline())

def LI(): return list(map(int,sys.stdin.readline().split()))

mod = 10**9 + 7

inf = float('inf')

ans = []



N, M = LI()

A = LI()

BC = [LI() for _ in range(M)]

A = list([x*(-1) for x in A])

heapq.heapify(A)

BC = sorted(BC, key=lambda x: x[1])[::-1]

#print(BC)

#print(A)

k = int(0)

ansC = int(0)

ansA = heapq.heappop(A)*(-1)

for i in range(N):

    if k<M and BC[k][0]==0:

        k +=1

    if k<M and BC[k][1]>ansA:

        ansC = BC[k][1]

        BC[k][0] -=1

    else:

        ansC = ansA

        if A!=[]:

            ansA = heapq.heappop(A)*(-1)

    ans.append(ansC)



#print(ans)

print((sum(ans)))



from heapq import heappush, heappop

# input
N, M = list(map(int, input().split()))
A = [0] * N
B = [0] * M
C = [0] * M
A = list(map(int, input().split()))
A.sort()
for i in range(M):
    B[i], C[i] = list(map(int, input().split()))


def solve():
    pairs = list(zip(C, B))
    sortedpairs = sorted(pairs, key=lambda x: x[0])
    for i in range(M):
        B[i] = sortedpairs[i][1]
        C[i] = sortedpairs[i][0]
    ansA = [0] * N
    for j in range(N):
        ansA[j] = A[j]
    p = int(0)
    j = int(0)
    while j < N and M >= 1 + p:
        jd = int(0)
        if ansA[j] >= C[M - 1 - p]:
            break
        while B[M - 1 - p] - jd > 0:
            if j == N:
                break
            if ansA[j] >= C[M - 1 - p]:
                break
            else:
                ansA[j] = C[M - 1 - p]
            jd += 1
            j += 1
        p += 1
    ans = int(0)
    for j in range(N):
        ans += ansA[j]
    print(ans)


solve()

import heapq
import sys


def I():
    return int(sys.stdin.readline())


def LI():
    return list(map(int, sys.stdin.readline().split()))


mod = 10**9 + 7
inf = float("inf")
ans = []
N, M = LI()
A = LI()
BC = [LI() for _ in range(M)]
A = list([x * (-1) for x in A])
heapq.heapify(A)
BC = sorted(BC, key=lambda x: x[1])[::-1]
# print(BC)
# print(A)
k = int(0)
ansC = int(0)
ansA = heapq.heappop(A) * (-1)
for i in range(N):
    if k < M and BC[k][0] == 0:
        k += 1
    if k < M and BC[k][1] > ansA:
        ansC = BC[k][1]
        BC[k][0] -= 1
    else:
        ansC = ansA
        if A != []:
            ansA = heapq.heappop(A) * (-1)
    ans.append(ansC)
# print(ans)
print((sum(ans)))

-from heapq import heappush, heappop - -# input -N, M = list(map(int, input().split())) -A = [0] * N -B = [0] * M -C = [0] * M -A = list(map(int, input().split())) -A.sort() -for i in range(M): -    B[i], C[i] = list(map(int, input().split())) +import heapq +import sys -def solve(): -    pairs = list(zip(C, B)) -    sortedpairs = sorted(pairs, key=lambda x: x[0]) -    for i in range(M): -        B[i] = sortedpairs[i][1] -        C[i] = sortedpairs[i][0] -    ansA = [0] * N -    for j in range(N): -        ansA[j] = A[j] -    p = int(0) -    j = int(0) -    while j < N and M >= 1 + p: -        jd = int(0) -        if ansA[j] >= C[M - 1 - p]: -            break -        while B[M - 1 - p] - jd > 0: -            if j == N: -                break -            if ansA[j] >= C[M - 1 - p]: -                break -            else: -                ansA[j] = C[M - 1 - p] -            jd += 1 -            j += 1 -        p += 1 -    ans = int(0) -    for j in range(N): -        ans += ansA[j] -    print(ans) +def I(): +    return int(sys.stdin.readline()) -solve() +def LI(): +    return list(map(int, sys.stdin.readline().split())) + + +mod = 10**9 + 7 +inf = float("inf") +ans = [] +N, M = LI() +A = LI() +BC = [LI() for _ in range(M)] +A = list([x * (-1) for x in A]) +heapq.heapify(A) +BC = sorted(BC, key=lambda x: x[1])[::-1] +# print(BC) +# print(A) +k = int(0) +ansC = int(0) +ansA = heapq.heappop(A) * (-1) +for i in range(N): +    if k < M and BC[k][0] == 0: +        k += 1 +    if k < M and BC[k][1] > ansA: +        ansC = BC[k][1] +        BC[k][0] -= 1 +    else: +        ansC = ansA +        if A != []: +            ansA = heapq.heappop(A) * (-1) +    ans.append(ansC) +# print(ans) +print((sum(ans)))