import collections
import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))
cnt = collections.Counter(a).most_common()
heapq.heapify(cnt)


for i, set_bc in enumerate(bc):
    now0,now1 = heapq.heappop(cnt)
    b,c = set_bc
    if now0 >= c:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
        continue
    tmpb = 0
    for j in range(b):
        if now0 < c:
            if now1 >= b:
                now1 -= b
                tmpb += b
                heapq.heappush(cnt,(c,tmpb))
                break
            tmpb += now1
            b -= now1
            now0,now1 = heapq.heappop(cnt)
        else:
            heapq.heappush(cnt,(c,tmpb))
            break
    if now1 != 0:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
if now1 != 0:
    heapq.heappush(cnt,(now0,now1))
ans = 0

for i in range(len(cnt)):
    val, num = heapq.heappop(cnt)
    ans += val * num
print(ans) import collections collections import heapq heapq 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 bc = [] bc [] for _ in range(m):
    b,c = map(int,input().split())
    bc.append((b,c)) _ range(m) range m b,c = map(int,input().split()) b map(int,input().split()) map int input().split() ().split () input split c bc.append((b,c)) bc.append bc append (b,c) b c cnt = collections.Counter(a).most_common() cnt collections.Counter(a).most_common() collections.Counter(a).most_common collections.Counter(a) collections.Counter collections Counter a most_common heapq.heapify(cnt) heapq.heapify heapq heapify cnt for i, set_bc in enumerate(bc):
    now0,now1 = heapq.heappop(cnt)
    b,c = set_bc
    if now0 >= c:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
        continue
    tmpb = 0
    for j in range(b):
        if now0 < c:
            if now1 >= b:
                now1 -= b
                tmpb += b
                heapq.heappush(cnt,(c,tmpb))
                break
            tmpb += now1
            b -= now1
            now0,now1 = heapq.heappop(cnt)
        else:
            heapq.heappush(cnt,(c,tmpb))
            break
    if now1 != 0:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0 i set_bc enumerate(bc) enumerate bc now0,now1 = heapq.heappop(cnt) now0 heapq.heappop(cnt) heapq.heappop heapq heappop cnt now1 b,c = set_bc b set_bc c if now0 >= c:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
        continue
     now0 >= c now0 c heapq.heappush(cnt,(now0,now1)) heapq.heappush heapq heappush cnt (now0,now1) now0 now1 now1 = 0 now1 0 continue tmpb = 0 tmpb 0 for j in range(b):
        if now0 < c:
            if now1 >= b:
                now1 -= b
                tmpb += b
                heapq.heappush(cnt,(c,tmpb))
                break
            tmpb += now1
            b -= now1
            now0,now1 = heapq.heappop(cnt)
        else:
            heapq.heappush(cnt,(c,tmpb))
            break
     j range(b) range b if now0 < c:
            if now1 >= b:
                now1 -= b
                tmpb += b
                heapq.heappush(cnt,(c,tmpb))
                break
            tmpb += now1
            b -= now1
            now0,now1 = heapq.heappop(cnt)
        else:
            heapq.heappush(cnt,(c,tmpb))
            break
     now0 < c now0 c if now1 >= b:
                now1 -= b
                tmpb += b
                heapq.heappush(cnt,(c,tmpb))
                break
             now1 >= b now1 b now1 -= b now1 b tmpb += b tmpb b heapq.heappush(cnt,(c,tmpb)) heapq.heappush heapq heappush cnt (c,tmpb) c tmpb break tmpb += now1 tmpb now1 b -= now1 b now1 now0,now1 = heapq.heappop(cnt) now0 heapq.heappop(cnt) heapq.heappop heapq heappop cnt now1 heapq.heappush(cnt,(c,tmpb)) heapq.heappush heapq heappush cnt (c,tmpb) c tmpb break if now1 != 0:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0 now1 != 0 now1 0 heapq.heappush(cnt,(now0,now1)) heapq.heappush heapq heappush cnt (now0,now1) now0 now1 now1 = 0 now1 0 if now1 != 0:
    heapq.heappush(cnt,(now0,now1)) now1 != 0 now1 0 heapq.heappush(cnt,(now0,now1)) heapq.heappush heapq heappush cnt (now0,now1) now0 now1 ans = 0 ans 0 for i in range(len(cnt)):
    val, num = heapq.heappop(cnt)
    ans += val * num i range(len(cnt)) range len(cnt) len cnt val, num = heapq.heappop(cnt) val heapq.heappop(cnt) heapq.heappop heapq heappop cnt num ans += val * num ans val * num val num print(ans) print ans c = map(int,input().split()) map(int,input().split()) c now1 = 0 0 now1 bc = [] [] bc now1 = heapq.heappop(cnt) heapq.heappop(cnt) now1 tmpb += b b tmpb now1 -= b b now1 ans = 0 0 ans cnt = collections.Counter(a).most_common() collections.Counter(a).most_common() cnt ans += val * num val * num ans tmpb += now1 now1 tmpb m = map(int,input().split()) map(int,input().split()) m b,c = map(int,input().split()) map(int,input().split()) b b -= now1 now1 b now0,now1 = heapq.heappop(cnt) heapq.heappop(cnt) now0 n,m = map(int,input().split()) map(int,input().split()) n c = set_bc set_bc c a = list(map(int,input().split())) list(map(int,input().split())) a b,c = set_bc set_bc b now0,now1 = heapq.heappop(cnt) heapq.heappop(cnt) now0 now1 = 0 0 now1 now1 = heapq.heappop(cnt) heapq.heappop(cnt) now1 num = heapq.heappop(cnt) heapq.heappop(cnt) num tmpb = 0 0 tmpb val, num = heapq.heappop(cnt) heapq.heappop(cnt) val
import collections
import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = []
for _ in range(m):
    b,c = map(int,input().split())
    bc.append((b,c))
cnt = collections.Counter(a).most_common()
heapq.heapify(cnt)


for i, set_bc in enumerate(bc):
    now0,now1 = heapq.heappop(cnt)
    b,c = set_bc
    if now0 >= c:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
        continue
    tmpb = 0
    for j in range(b):
        if now0 < c:
            if now1 >= b:
                now1 -= b
                tmpb += b
                heapq.heappush(cnt,(c,tmpb))
                break
            tmpb += now1
            b -= now1
            now0,now1 = heapq.heappop(cnt)
        else:
            heapq.heappush(cnt,(c,tmpb))
            break
    if now1 != 0:
        heapq.heappush(cnt,(now0,now1))
        now1 = 0
if now1 != 0:
    heapq.heappush(cnt,(now0,now1))
ans = 0

for i in range(len(cnt)):
    val, num = heapq.heappop(cnt)
    ans += val * num
print(ans)
