import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
As = list(mapint())
As.sort()

BC = [list(mapint()) for _ in range(M)]
BC.sort(key=lambda x: x[1])

cum = 0
for b, c in BC[::-1]:
    if c<As[0]:
        break
    As.extend([c]*b)
    cum += b
    if cum>=N:
        break

As.sort(reverse=True)
print(sum(As[:N])) import sys sys def input(): return sys.stdin.readline().strip() input def mapint(): return map(int, input().split()) mapint sys.setrecursionlimit(10**9) sys.setrecursionlimit sys setrecursionlimit 10**9 10 9 N, M = mapint() N mapint() mapint M As = list(mapint()) As list(mapint()) list mapint() mapint As.sort() As.sort As sort list(mapint()) for _ in range(M) for _ in range(M) _ range(M) range M for _ in range(M) list(mapint()) list mapint() mapint BC = [list(mapint()) for _ in range(M)] BC [list(mapint()) for _ in range(M)] BC.sort(key=lambda x: x[1]) BC.sort BC sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x cum = 0 cum 0 for b, c in BC[::-1]:
    if c<As[0]:
        break
    As.extend([c]*b)
    cum += b
    if cum>=N:
        break b c BC[::-1] BC ::-1 -1 if c<As[0]:
        break
     c<As[0] c As[0] As 0 break As.extend([c]*b) As.extend As extend [c]*b [c] c b cum += b cum b if cum>=N:
        break cum>=N cum N break As.sort(reverse=True) As.sort As sort reverse=True reverse True print(sum(As[:N])) print sum(As[:N]) sum As[:N] As :N N As = list(mapint()) list(mapint()) As def mapint(): return map(int, input().split()) def mapint(): return map(int, input().split()) mapint cum = 0 0 cum N, M = mapint() mapint() N cum += b b cum def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input M = mapint() mapint() M BC = [list(mapint()) for _ in range(M)] [list(mapint()) for _ in range(M)] BC
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
As = list(mapint())
As.sort()

BC = [list(mapint()) for _ in range(M)]
BC.sort(key=lambda x: x[1])

cum = 0
for b, c in BC[::-1]:
    if c<As[0]:
        break
    As.extend([c]*b)
    cum += b
    if cum>=N:
        break

As.sort(reverse=True)
print(sum(As[:N]))