from collections import deque

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
a = deque(a)
l = []
ans = []

for i in range(m):
    b, c = map(int, input().split())
    l.append([c, b])

l = sorted(l)[::-1]
ref = a.popleft()

for num, cnt in l:
    while ref >= num:
        ans.append(ref)
        if len(a) == 0:
            print(sum(ans))
            exit()
        ref = a.popleft()

    while cnt > 0:
        if ref < num:
            ans.append(num)
            cnt -= 1
            if len(a) == 0:
                print(sum(ans))
                exit()
            ref = a.popleft()
        else:
            break

ans.append(ref)

while a:
    ref = a.popleft()
    ans.append(ref)

print(sum(ans)) from collections import deque n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m a = sorted(list(map(int, input().split()))) a sorted(list(map(int, input().split()))) sorted list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split a = deque(a) a deque(a) deque a l = [] l [] ans = [] ans [] for i in range(m):
    b, c = map(int, input().split())
    l.append([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 l.append([c, b]) l.append l append [c, b] c b l = sorted(l)[::-1] l sorted(l)[::-1] (l) sorted l ::-1 -1 ref = a.popleft() ref a.popleft() a.popleft a popleft for num, cnt in l:
    while ref >= num:
        ans.append(ref)
        if len(a) == 0:
            print(sum(ans))
            exit()
        ref = a.popleft()

    while cnt > 0:
        if ref < num:
            ans.append(num)
            cnt -= 1
            if len(a) == 0:
                print(sum(ans))
                exit()
            ref = a.popleft()
        else:
            break num cnt l while ref >= num:
        ans.append(ref)
        if len(a) == 0:
            print(sum(ans))
            exit()
        ref = a.popleft()

     ref >= num ref num ans.append(ref) ans.append ans append ref if len(a) == 0:
            print(sum(ans))
            exit()
         len(a) == 0 len(a) len a 0 print(sum(ans)) print sum(ans) sum ans exit() exit ref = a.popleft() ref a.popleft() a.popleft a popleft while cnt > 0:
        if ref < num:
            ans.append(num)
            cnt -= 1
            if len(a) == 0:
                print(sum(ans))
                exit()
            ref = a.popleft()
        else:
            break cnt > 0 cnt 0 if ref < num:
            ans.append(num)
            cnt -= 1
            if len(a) == 0:
                print(sum(ans))
                exit()
            ref = a.popleft()
        else:
            break ref < num ref num ans.append(num) ans.append ans append num cnt -= 1 cnt 1 if len(a) == 0:
                print(sum(ans))
                exit()
             len(a) == 0 len(a) len a 0 print(sum(ans)) print sum(ans) sum ans exit() exit ref = a.popleft() ref a.popleft() a.popleft a popleft break ans.append(ref) ans.append ans append ref while a:
    ref = a.popleft()
    ans.append(ref) a ref = a.popleft() ref a.popleft() a.popleft a popleft ans.append(ref) ans.append ans append ref print(sum(ans)) print sum(ans) sum ans c = map(int, input().split()) map(int, input().split()) c m = map(int, input().split()) map(int, input().split()) m ref = a.popleft() a.popleft() ref l = [] [] l ref = a.popleft() a.popleft() ref a = sorted(list(map(int, input().split()))) sorted(list(map(int, input().split()))) a ref = a.popleft() a.popleft() ref cnt -= 1 1 cnt ans = [] [] ans l = sorted(l)[::-1] sorted(l)[::-1] l a = deque(a) deque(a) a ref = a.popleft() a.popleft() ref b, c = map(int, input().split()) map(int, input().split()) b n, m = map(int, input().split()) map(int, input().split()) n
from collections import deque

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
a = deque(a)
l = []
ans = []

for i in range(m):
    b, c = map(int, input().split())
    l.append([c, b])

l = sorted(l)[::-1]
ref = a.popleft()

for num, cnt in l:
    while ref >= num:
        ans.append(ref)
        if len(a) == 0:
            print(sum(ans))
            exit()
        ref = a.popleft()

    while cnt > 0:
        if ref < num:
            ans.append(num)
            cnt -= 1
            if len(a) == 0:
                print(sum(ans))
                exit()
            ref = a.popleft()
        else:
            break

ans.append(ref)

while a:
    ref = a.popleft()
    ans.append(ref)

print(sum(ans))