# ABC127 D
from bisect import bisect_left as bl

f=lambda:map(int,input().split())
N,M=f()
A=list(f())
A.sort()
BC=[]
for _ in [0]*M:
    BC.append(tuple(f()))
BC.sort(key=lambda x:x[1])
res=0
num=0
def compare():
    # True => Aが大きい
    if not A:
        return False
    if not BC:
        return True
    return A[-1]>BC[-1][1]

while 1:
    if compare():
        res+=A.pop()
        num+=1
    else:
        b,c=BC.pop()
        if b+num<=N:
            res+=c*b
            num+=b
        else:
            res+=c*(N-num)
            num+=(N-num)
    if num==N:
        break
print(res) from bisect import bisect_left as bl f=lambda:map(int,input().split()) f lambda:map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split N,M=f() N f() f M A=list(f()) A list(f()) list f() f A.sort() A.sort A sort BC=[] BC [] for _ in [0]*M:
    BC.append(tuple(f())) _ [0]*M [0] 0 M BC.append(tuple(f())) BC.append BC append tuple(f()) tuple f() f 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 res=0 res 0 num=0 num 0 def compare():
    # True => Aが大きい
    if not A:
        return False
    if not BC:
        return True
    return A[-1]>BC[-1][1] compare if not A:
        return False
     not A A return False False if not BC:
        return True
     not BC BC return True True return A[-1]>BC[-1][1] A[-1]>BC[-1][1] A[-1] A -1 BC[-1][1] [-1] BC -1 1 while 1:
    if compare():
        res+=A.pop()
        num+=1
    else:
        b,c=BC.pop()
        if b+num<=N:
            res+=c*b
            num+=b
        else:
            res+=c*(N-num)
            num+=(N-num)
    if num==N:
        break 1 if compare():
        res+=A.pop()
        num+=1
    else:
        b,c=BC.pop()
        if b+num<=N:
            res+=c*b
            num+=b
        else:
            res+=c*(N-num)
            num+=(N-num)
     compare() compare res+=A.pop() res A.pop() A.pop A pop num+=1 num 1 b,c=BC.pop() b BC.pop() BC.pop BC pop c if b+num<=N:
            res+=c*b
            num+=b
        else:
            res+=c*(N-num)
            num+=(N-num)
     b+num<=N b+num b num N res+=c*b res c*b c b num+=b num b res+=c*(N-num) res c*(N-num) c N-num N num num+=(N-num) num N-num N num if num==N:
        break num==N num N break print(res) print res res+=c*b c*b res num+=1 1 num b,c=BC.pop() BC.pop() b num+=b b num def compare():
    # True => Aが大きい
    if not A:
        return False
    if not BC:
        return True
    return A[-1]>BC[-1][1] def compare():
    # True => Aが大きい
    if not A:
        return False
    if not BC:
        return True
    return A[-1]>BC[-1][1] compare res+=c*(N-num) c*(N-num) res BC=[] [] BC num=0 0 num c=BC.pop() BC.pop() c A=list(f()) list(f()) A f=lambda:map(int,input().split()) lambda:map(int,input().split()) f N,M=f() f() N num+=(N-num) N-num num M=f() f() M res+=A.pop() A.pop() res res=0 0 res
# ABC127 D
from bisect import bisect_left as bl

f=lambda:map(int,input().split())
N,M=f()
A=list(f())
A.sort()
BC=[]
for _ in [0]*M:
    BC.append(tuple(f()))
BC.sort(key=lambda x:x[1])
res=0
num=0
def compare():
    # True => Aが大きい
    if not A:
        return False
    if not BC:
        return True
    return A[-1]>BC[-1][1]

while 1:
    if compare():
        res+=A.pop()
        num+=1
    else:
        b,c=BC.pop()
        if b+num<=N:
            res+=c*b
            num+=b
        else:
            res+=c*(N-num)
            num+=(N-num)
    if num==N:
        break
print(res)