import heapq
n, m = map(int, input().split())
_a = list(map(int, input().split()))
a = [-i for i in _a]
lc = set()
bcount = dict()
heapq.heapify(a)
for i in range(m):
    b, c = map(int, input().split())
    lc.add(-c)
    if str(c) in bcount.keys():
        bcount[str(c)] += b
    else:
        bcount[str(c)] = b


lc = list(lc)
heapq.heapify(lc)

cnt = 0
ans = 0

while cnt < n:
    amax = -a[0]
    cmax = -1 if len(lc) == 0 else -lc[0]
    if amax >= cmax:
        cnt += 1
        ans += heapq.heappop(a)
    else:
        take = min(n - cnt, bcount[str(cmax)])
        cnt += take
        ans += heapq.heappop(lc) * take

print(-ans) 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 -i for i in _a for i in _a i _a for i in _a -i i a = [-i for i in _a] a [-i for i in _a] lc = set() lc set() set bcount = dict() bcount dict() dict heapq.heapify(a) heapq.heapify heapq heapify a for i in range(m):
    b, c = map(int, input().split())
    lc.add(-c)
    if str(c) in bcount.keys():
        bcount[str(c)] += b
    else:
        bcount[str(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 lc.add(-c) lc.add lc add -c c if str(c) in bcount.keys():
        bcount[str(c)] += b
    else:
        bcount[str(c)] = b str(c) in bcount.keys() str(c) str c bcount.keys() bcount.keys bcount keys bcount[str(c)] += b bcount[str(c)] bcount str(c) str c b bcount[str(c)] = b bcount[str(c)] bcount str(c) str c b lc = list(lc) lc list(lc) list lc heapq.heapify(lc) heapq.heapify heapq heapify lc cnt = 0 cnt 0 ans = 0 ans 0 while cnt < n:
    amax = -a[0]
    cmax = -1 if len(lc) == 0 else -lc[0]
    if amax >= cmax:
        cnt += 1
        ans += heapq.heappop(a)
    else:
        take = min(n - cnt, bcount[str(cmax)])
        cnt += take
        ans += heapq.heappop(lc) * take cnt < n cnt n amax = -a[0] amax -a[0] a[0] a 0 cmax = -1 if len(lc) == 0 else -lc[0] cmax -1 if len(lc) == 0 else -lc[0] len(lc) == 0 len(lc) len lc 0 -1 -lc[0] lc[0] lc 0 if amax >= cmax:
        cnt += 1
        ans += heapq.heappop(a)
    else:
        take = min(n - cnt, bcount[str(cmax)])
        cnt += take
        ans += heapq.heappop(lc) * take amax >= cmax amax cmax cnt += 1 cnt 1 ans += heapq.heappop(a) ans heapq.heappop(a) heapq.heappop heapq heappop a take = min(n - cnt, bcount[str(cmax)]) take min(n - cnt, bcount[str(cmax)]) min n - cnt n cnt bcount[str(cmax)] bcount str(cmax) str cmax cnt += take cnt take ans += heapq.heappop(lc) * take ans heapq.heappop(lc) * take heapq.heappop(lc) heapq.heappop heapq heappop lc take print(-ans) print -ans ans ans += heapq.heappop(lc) * take heapq.heappop(lc) * take ans a = [-i for i in _a] [-i for i in _a] a b, c = map(int, input().split()) map(int, input().split()) b ans = 0 0 ans _a = list(map(int, input().split())) list(map(int, input().split())) _a m = map(int, input().split()) map(int, input().split()) m take = min(n - cnt, bcount[str(cmax)]) min(n - cnt, bcount[str(cmax)]) take ans += heapq.heappop(a) heapq.heappop(a) ans amax = -a[0] -a[0] amax lc = list(lc) list(lc) lc cmax = -1 if len(lc) == 0 else -lc[0] -1 if len(lc) == 0 else -lc[0] cmax n, m = map(int, input().split()) map(int, input().split()) n cnt += take take cnt c = map(int, input().split()) map(int, input().split()) c cnt += 1 1 cnt bcount = dict() dict() bcount lc = set() set() lc cnt = 0 0 cnt
import heapq
n, m = map(int, input().split())
_a = list(map(int, input().split()))
a = [-i for i in _a]
lc = set()
bcount = dict()
heapq.heapify(a)
for i in range(m):
    b, c = map(int, input().split())
    lc.add(-c)
    if str(c) in bcount.keys():
        bcount[str(c)] += b
    else:
        bcount[str(c)] = b


lc = list(lc)
heapq.heapify(lc)

cnt = 0
ans = 0

while cnt < n:
    amax = -a[0]
    cmax = -1 if len(lc) == 0 else -lc[0]
    if amax >= cmax:
        cnt += 1
        ans += heapq.heappop(a)
    else:
        take = min(n - cnt, bcount[str(cmax)])
        cnt += take
        ans += heapq.heappop(lc) * take

print(-ans)
