from collections import Counter
import heapq

n,m = map(int,input().split())
l = list(map(int,input().split()))

hq  = sorted(tuple(Counter(l).items()), key=lambda x:x[0])

heapq.heapify(hq)
# print(hq)
BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC,key = lambda x:-x[1])

for b,c in BC:
    while b > 0:
        x,y = heapq.heappop(hq)
        if x < c:
            if b < y:
                heapq.heappush(hq,(c,b))
                heapq.heappush(hq,(x,y-b))
                b = 0
            else:
                heapq.heappush(hq,(c,y))
                b -= y
        else:
            heapq.heappush(hq,(x,y))
            break
    # print(hq)

ans = 0
for i in range(len(hq)):
    ans += hq[i][0]*hq[i][1]
print(ans) from collections import Counter import heapq heapq n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m l = list(map(int,input().split())) l list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split hq  = sorted(tuple(Counter(l).items()), key=lambda x:x[0]) hq sorted(tuple(Counter(l).items()), key=lambda x:x[0]) sorted tuple(Counter(l).items()) tuple Counter(l).items() (l).items (l) Counter l items key=lambda x:x[0] key lambda x:x[0] x[0] x 0 x heapq.heapify(hq) heapq.heapify heapq heapify hq list(map(int, input().split())) for i in range(m) for i in range(m) i range(m) range m for i in range(m) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split BC = [list(map(int, input().split())) for i in range(m)] BC [list(map(int, input().split())) for i in range(m)] BC = sorted(BC,key = lambda x:-x[1]) BC sorted(BC,key = lambda x:-x[1]) sorted BC key = lambda x:-x[1] key lambda x:-x[1] -x[1] x[1] x 1 x for b,c in BC:
    while b > 0:
        x,y = heapq.heappop(hq)
        if x < c:
            if b < y:
                heapq.heappush(hq,(c,b))
                heapq.heappush(hq,(x,y-b))
                b = 0
            else:
                heapq.heappush(hq,(c,y))
                b -= y
        else:
            heapq.heappush(hq,(x,y))
            break
    # print(hq) b c BC while b > 0:
        x,y = heapq.heappop(hq)
        if x < c:
            if b < y:
                heapq.heappush(hq,(c,b))
                heapq.heappush(hq,(x,y-b))
                b = 0
            else:
                heapq.heappush(hq,(c,y))
                b -= y
        else:
            heapq.heappush(hq,(x,y))
            break
    # print(hq) b > 0 b 0 x,y = heapq.heappop(hq) x heapq.heappop(hq) heapq.heappop heapq heappop hq y if x < c:
            if b < y:
                heapq.heappush(hq,(c,b))
                heapq.heappush(hq,(x,y-b))
                b = 0
            else:
                heapq.heappush(hq,(c,y))
                b -= y
        else:
            heapq.heappush(hq,(x,y))
            break
    # print(hq) x < c x c if b < y:
                heapq.heappush(hq,(c,b))
                heapq.heappush(hq,(x,y-b))
                b = 0
            else:
                heapq.heappush(hq,(c,y))
                b -= y
         b < y b y heapq.heappush(hq,(c,b)) heapq.heappush heapq heappush hq (c,b) c b heapq.heappush(hq,(x,y-b)) heapq.heappush heapq heappush hq (x,y-b) x y-b y b b = 0 b 0 heapq.heappush(hq,(c,y)) heapq.heappush heapq heappush hq (c,y) c y b -= y b y heapq.heappush(hq,(x,y)) heapq.heappush heapq heappush hq (x,y) x y break ans = 0 ans 0 for i in range(len(hq)):
    ans += hq[i][0]*hq[i][1] i range(len(hq)) range len(hq) len hq ans += hq[i][0]*hq[i][1] ans hq[i][0]*hq[i][1] hq[i][0] [i] hq i 0 hq[i][1] [i] hq i 1 print(ans) print ans hq  = sorted(tuple(Counter(l).items()), key=lambda x:x[0]) sorted(tuple(Counter(l).items()), key=lambda x:x[0]) hq ans += hq[i][0]*hq[i][1] hq[i][0]*hq[i][1] ans l = list(map(int,input().split())) list(map(int,input().split())) l x,y = heapq.heappop(hq) heapq.heappop(hq) x m = map(int,input().split()) map(int,input().split()) m y = heapq.heappop(hq) heapq.heappop(hq) y BC = [list(map(int, input().split())) for i in range(m)] [list(map(int, input().split())) for i in range(m)] BC n,m = map(int,input().split()) map(int,input().split()) n b -= y y b BC = sorted(BC,key = lambda x:-x[1]) sorted(BC,key = lambda x:-x[1]) BC ans = 0 0 ans b = 0 0 b
from collections import Counter
import heapq

n,m = map(int,input().split())
l = list(map(int,input().split()))

hq  = sorted(tuple(Counter(l).items()), key=lambda x:x[0])

heapq.heapify(hq)
# print(hq)
BC = [list(map(int, input().split())) for i in range(m)]
BC = sorted(BC,key = lambda x:-x[1])

for b,c in BC:
    while b > 0:
        x,y = heapq.heappop(hq)
        if x < c:
            if b < y:
                heapq.heappush(hq,(c,b))
                heapq.heappush(hq,(x,y-b))
                b = 0
            else:
                heapq.heappush(hq,(c,y))
                b -= y
        else:
            heapq.heappush(hq,(x,y))
            break
    # print(hq)

ans = 0
for i in range(len(hq)):
    ans += hq[i][0]*hq[i][1]
print(ans)