import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    A=LI()
    B=[0]*M
    C=[0]*M
    for i in range(M):
        B[i],C[i]=MI()
    
    C,B=zip(*sorted(zip(C,B)))
    B=B[::-1]
    C=C[::-1]
    
    import heapq
    heapq.heapify(A)
    
    for i in range(M):
        b=B[i]
        c=C[i]
        for _ in range(b):
            a=heapq.heappop(A)
            if a>=c:
                heapq.heappush(A,a)
                break
            else:
                heapq.heappush(A,c)
                
    ans=0
    for i in range(N):
        a=heapq.heappop(A)
        ans+=a
        
    print(ans)

main() import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def I(): return int(input()) I def MI(): return map(int, input().split()) MI def LI(): return list(map(int, input().split())) LI def main():
    mod=10**9+7
    N,M=MI()
    A=LI()
    B=[0]*M
    C=[0]*M
    for i in range(M):
        B[i],C[i]=MI()
    
    C,B=zip(*sorted(zip(C,B)))
    B=B[::-1]
    C=C[::-1]
    
    import heapq
    heapq.heapify(A)
    
    for i in range(M):
        b=B[i]
        c=C[i]
        for _ in range(b):
            a=heapq.heappop(A)
            if a>=c:
                heapq.heappush(A,a)
                break
            else:
                heapq.heappush(A,c)
                
    ans=0
    for i in range(N):
        a=heapq.heappop(A)
        ans+=a
        
    print(ans) main mod=10**9+7 mod 10**9+7 10**9 10 9 7 N,M=MI() N MI() MI M A=LI() A LI() LI B=[0]*M B [0]*M [0] 0 M C=[0]*M C [0]*M [0] 0 M for i in range(M):
        B[i],C[i]=MI()
    
     i range(M) range M B[i],C[i]=MI() B[i] B i MI() MI C[i] C i C,B=zip(*sorted(zip(C,B))) C zip(*sorted(zip(C,B))) zip *sorted(zip(C,B)) sorted(zip(C,B)) sorted zip(C,B) zip C B B B=B[::-1] B B[::-1] B ::-1 -1 C=C[::-1] C C[::-1] C ::-1 -1 import heapq heapq heapq.heapify(A) heapq.heapify heapq heapify A for i in range(M):
        b=B[i]
        c=C[i]
        for _ in range(b):
            a=heapq.heappop(A)
            if a>=c:
                heapq.heappush(A,a)
                break
            else:
                heapq.heappush(A,c)
                
     i range(M) range M b=B[i] b B[i] B i c=C[i] c C[i] C i for _ in range(b):
            a=heapq.heappop(A)
            if a>=c:
                heapq.heappush(A,a)
                break
            else:
                heapq.heappush(A,c)
                
     _ range(b) range b a=heapq.heappop(A) a heapq.heappop(A) heapq.heappop heapq heappop A if a>=c:
                heapq.heappush(A,a)
                break
            else:
                heapq.heappush(A,c)
                
     a>=c a c heapq.heappush(A,a) heapq.heappush heapq heappush A a break heapq.heappush(A,c) heapq.heappush heapq heappush A c ans=0 ans 0 for i in range(N):
        a=heapq.heappop(A)
        ans+=a
        
     i range(N) range N a=heapq.heappop(A) a heapq.heappop(A) heapq.heappop heapq heappop A ans+=a ans a print(ans) print ans main() main def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI input = sys.stdin.readline sys.stdin.readline input def I(): return int(input()) def I(): return int(input()) I def main():
    mod=10**9+7
    N,M=MI()
    A=LI()
    B=[0]*M
    C=[0]*M
    for i in range(M):
        B[i],C[i]=MI()
    
    C,B=zip(*sorted(zip(C,B)))
    B=B[::-1]
    C=C[::-1]
    
    import heapq
    heapq.heapify(A)
    
    for i in range(M):
        b=B[i]
        c=C[i]
        for _ in range(b):
            a=heapq.heappop(A)
            if a>=c:
                heapq.heappush(A,a)
                break
            else:
                heapq.heappush(A,c)
                
    ans=0
    for i in range(N):
        a=heapq.heappop(A)
        ans+=a
        
    print(ans) def main():
    mod=10**9+7
    N,M=MI()
    A=LI()
    B=[0]*M
    C=[0]*M
    for i in range(M):
        B[i],C[i]=MI()
    
    C,B=zip(*sorted(zip(C,B)))
    B=B[::-1]
    C=C[::-1]
    
    import heapq
    heapq.heapify(A)
    
    for i in range(M):
        b=B[i]
        c=C[i]
        for _ in range(b):
            a=heapq.heappop(A)
            if a>=c:
                heapq.heappush(A,a)
                break
            else:
                heapq.heappush(A,c)
                
    ans=0
    for i in range(N):
        a=heapq.heappop(A)
        ans+=a
        
    print(ans) main def MI(): return map(int, input().split()) def MI(): return map(int, input().split()) MI
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    A=LI()
    B=[0]*M
    C=[0]*M
    for i in range(M):
        B[i],C[i]=MI()
    
    C,B=zip(*sorted(zip(C,B)))
    B=B[::-1]
    C=C[::-1]
    
    import heapq
    heapq.heapify(A)
    
    for i in range(M):
        b=B[i]
        c=C[i]
        for _ in range(b):
            a=heapq.heappop(A)
            if a>=c:
                heapq.heappush(A,a)
                break
            else:
                heapq.heappush(A,c)
                
    ans=0
    for i in range(N):
        a=heapq.heappop(A)
        ans+=a
        
    print(ans)

main()
