import sys

input = sys.stdin.readline



def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))



def main():

    mod=10**9+7

    N,M=MI()

    A=LI()

    CB=[[0,0]for _ in range(M)]

    A.sort()

    for i in range(M):

        CB[i][1],CB[i][0]=MI()

        

    CB.sort(reverse=True)

    now=0

    

    for i in range(N):

        if CB[now][1]<=0:

            now+=1

        

        if now>=M:

            break    

        

        ch=CB[now][0]

        if A[i]<ch:

            A[i]=ch

            CB[now][1]-=1

        else:

            break

        

    print((sum(A)))

    



main()

import sys

input = sys.stdin.readline



def I(): return int(eval(input()))

def MI(): return list(map(int, input().split()))

def LI(): return list(map(int, input().split()))



def main():

    mod=10**9+7

    N,M=MI()

    A=LI()

    B=[0]*M

    C=[0]*M

    for i in range(M):

        B[i],C[i]=MI()

    

    C,B=list(zip(*sorted(zip(C,B))))

    B=B[::-1]

    C=C[::-1]

    

    import heapq

    heapq.heapify(A)

    

    for i in range(M):

        b=B[i]

        c=C[i]

        for _ in range(b):

            a=heapq.heappop(A)

            if a>=c:

                heapq.heappush(A,a)

                break

            else:

                heapq.heappush(A,c)

                

    ans=0

    for i in range(N):

        a=heapq.heappop(A)

        ans+=a

        

    print(ans)



main()

import sys

input = sys.stdin.readline


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def main():
    mod = 10**9 + 7
    N, M = MI()
    A = LI()
    CB = [[0, 0] for _ in range(M)]
    A.sort()
    for i in range(M):
        CB[i][1], CB[i][0] = MI()
    CB.sort(reverse=True)
    now = 0
    for i in range(N):
        if CB[now][1] <= 0:
            now += 1
        if now >= M:
            break
        ch = CB[now][0]
        if A[i] < ch:
            A[i] = ch
            CB[now][1] -= 1
        else:
            break
    print((sum(A)))


main()

import sys

input = sys.stdin.readline


def I():
    return int(eval(input()))


def MI():
    return list(map(int, input().split()))


def LI():
    return list(map(int, input().split()))


def main():
    mod = 10**9 + 7
    N, M = MI()
    A = LI()
    B = [0] * M
    C = [0] * M
    for i in range(M):
        B[i], C[i] = MI()
    C, B = list(zip(*sorted(zip(C, B))))
    B = B[::-1]
    C = C[::-1]
    import heapq

    heapq.heapify(A)
    for i in range(M):
        b = B[i]
        c = C[i]
        for _ in range(b):
            a = heapq.heappop(A)
            if a >= c:
                heapq.heappush(A, a)
                break
            else:
                heapq.heappush(A, c)
    ans = 0
    for i in range(N):
        a = heapq.heappop(A)
        ans += a
    print(ans)


main()

-    CB = [[0, 0] for _ in range(M)] -    A.sort() +    B = [0] * M +    C = [0] * M -        CB[i][1], CB[i][0] = MI() -    CB.sort(reverse=True) -    now = 0 +        B[i], C[i] = MI() +    C, B = list(zip(*sorted(zip(C, B)))) +    B = B[::-1] +    C = C[::-1] +    import heapq + +    heapq.heapify(A) +    for i in range(M): +        b = B[i] +        c = C[i] +        for _ in range(b): +            a = heapq.heappop(A) +            if a >= c: +                heapq.heappush(A, a) +                break +            else: +                heapq.heappush(A, c) +    ans = 0 -        if CB[now][1] <= 0: -            now += 1 -        if now >= M: -            break -        ch = CB[now][0] -        if A[i] < ch: -            A[i] = ch -            CB[now][1] -= 1 -        else: -            break -    print((sum(A))) +        a = heapq.heappop(A) +        ans += a +    print(ans)