#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush,heapify
from bisect import bisect_left

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    q = []
    for i in range(M):
        B, C = map(int, input().split())
        heappush(q,(-C,B))
    
    ans = 0
    index = 0
    # print(A)
    while q:
        c,b = heappop(q)
        c *= -1
        # print(c,b)
        count = 0
        for i in range(b):
            if i + index == N:
                break
            if c > A[index+i]:
                ans += c
                count += 1
            else:
                break

        # print(ans,index)
        if count < b:
            index += count
            break
        else:
            index += count
            
    print(ans + sum(A[index:]))

if __name__ == "__main__":
    main() from collections import deque, Counter from heapq import heappop, heappush,heapify from bisect import bisect_left def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    q = []
    for i in range(M):
        B, C = map(int, input().split())
        heappush(q,(-C,B))
    
    ans = 0
    index = 0
    # print(A)
    while q:
        c,b = heappop(q)
        c *= -1
        # print(c,b)
        count = 0
        for i in range(b):
            if i + index == N:
                break
            if c > A[index+i]:
                ans += c
                count += 1
            else:
                break

        # print(ans,index)
        if count < b:
            index += count
            break
        else:
            index += count
            
    print(ans + sum(A[index:])) main 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 A.sort() A.sort A sort q = [] q [] for i in range(M):
        B, C = map(int, input().split())
        heappush(q,(-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 heappush(q,(-C,B)) heappush q (-C,B) -C C B ans = 0 ans 0 index = 0 index 0 while q:
        c,b = heappop(q)
        c *= -1
        # print(c,b)
        count = 0
        for i in range(b):
            if i + index == N:
                break
            if c > A[index+i]:
                ans += c
                count += 1
            else:
                break

        # print(ans,index)
        if count < b:
            index += count
            break
        else:
            index += count
            
     q c,b = heappop(q) c heappop(q) heappop q b c *= -1 c -1 count = 0 count 0 for i in range(b):
            if i + index == N:
                break
            if c > A[index+i]:
                ans += c
                count += 1
            else:
                break

        # print(ans,index)
         i range(b) range b if i + index == N:
                break
             i + index == N i + index i index N break if c > A[index+i]:
                ans += c
                count += 1
            else:
                break

        # print(ans,index)
         c > A[index+i] c A[index+i] A index+i index i ans += c ans c count += 1 count 1 break if count < b:
            index += count
            break
        else:
            index += count
            
     count < b count b index += count index count break index += count index count print(ans + sum(A[index:])) print ans + sum(A[index:]) ans sum(A[index:]) sum A[index:] A index: index if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    q = []
    for i in range(M):
        B, C = map(int, input().split())
        heappush(q,(-C,B))
    
    ans = 0
    index = 0
    # print(A)
    while q:
        c,b = heappop(q)
        c *= -1
        # print(c,b)
        count = 0
        for i in range(b):
            if i + index == N:
                break
            if c > A[index+i]:
                ans += c
                count += 1
            else:
                break

        # print(ans,index)
        if count < b:
            index += count
            break
        else:
            index += count
            
    print(ans + sum(A[index:])) def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    q = []
    for i in range(M):
        B, C = map(int, input().split())
        heappush(q,(-C,B))
    
    ans = 0
    index = 0
    # print(A)
    while q:
        c,b = heappop(q)
        c *= -1
        # print(c,b)
        count = 0
        for i in range(b):
            if i + index == N:
                break
            if c > A[index+i]:
                ans += c
                count += 1
            else:
                break

        # print(ans,index)
        if count < b:
            index += count
            break
        else:
            index += count
            
    print(ans + sum(A[index:])) main
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush,heapify
from bisect import bisect_left

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    q = []
    for i in range(M):
        B, C = map(int, input().split())
        heappush(q,(-C,B))
    
    ans = 0
    index = 0
    # print(A)
    while q:
        c,b = heappop(q)
        c *= -1
        # print(c,b)
        count = 0
        for i in range(b):
            if i + index == N:
                break
            if c > A[index+i]:
                ans += c
                count += 1
            else:
                break

        # print(ans,index)
        if count < b:
            index += count
            break
        else:
            index += count
            
    print(ans + sum(A[index:]))

if __name__ == "__main__":
    main()
