def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    from heapq import heappop, heappush, heapreplace
    a = list(map(int, input().split()))
    from collections import Counter as cc
    a = cc(a)
    q = []
    for key in a:
        heappush(q, (key, a[key]))
    for i in range(m):
        b, c = map(int, input().split())
        now = b
        while q:
            num, cnt = q[0]
            if c <= num: break
            
            if now >= cnt:
                now -= cnt
                heappop(q)
            else:
                heapreplace(q, (num, cnt-now))
                now = 0
                break
        if now != b:
            heappush(q, (c, b-now))
    ans = 0
    for num, cnt in q:
        ans += num*cnt
    print(ans)



if __name__ == '__main__':
    main() def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    from heapq import heappop, heappush, heapreplace
    a = list(map(int, input().split()))
    from collections import Counter as cc
    a = cc(a)
    q = []
    for key in a:
        heappush(q, (key, a[key]))
    for i in range(m):
        b, c = map(int, input().split())
        now = b
        while q:
            num, cnt = q[0]
            if c <= num: break
            
            if now >= cnt:
                now -= cnt
                heappop(q)
            else:
                heapreplace(q, (num, cnt-now))
                now = 0
                break
        if now != b:
            heappush(q, (c, b-now))
    ans = 0
    for num, cnt in q:
        ans += num*cnt
    print(ans) main import sys sys def input(): return sys.stdin.readline().rstrip()
    
     input n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m from heapq import heappop, heappush, heapreplace a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split from collections import Counter as cc a = cc(a) a cc(a) cc a q = [] q [] for key in a:
        heappush(q, (key, a[key]))
     key a heappush(q, (key, a[key])) heappush q (key, a[key]) key a[key] a key for i in range(m):
        b, c = map(int, input().split())
        now = b
        while q:
            num, cnt = q[0]
            if c <= num: break
            
            if now >= cnt:
                now -= cnt
                heappop(q)
            else:
                heapreplace(q, (num, cnt-now))
                now = 0
                break
        if now != b:
            heappush(q, (c, b-now))
     i range(m) range m b, c = map(int, input().split()) b map(int, input().split()) map int input().split() ().split () input split c now = b now b while q:
            num, cnt = q[0]
            if c <= num: break
            
            if now >= cnt:
                now -= cnt
                heappop(q)
            else:
                heapreplace(q, (num, cnt-now))
                now = 0
                break
         q num, cnt = q[0] num q[0] q 0 cnt if c <= num: break
            
             c <= num c num if now >= cnt:
                now -= cnt
                heappop(q)
            else:
                heapreplace(q, (num, cnt-now))
                now = 0
                break
         now >= cnt now cnt now -= cnt now cnt heappop(q) heappop q heapreplace(q, (num, cnt-now)) heapreplace q (num, cnt-now) num cnt-now cnt now now = 0 now 0 break if now != b:
            heappush(q, (c, b-now))
     now != b now b heappush(q, (c, b-now)) heappush q (c, b-now) c b-now b now ans = 0 ans 0 for num, cnt in q:
        ans += num*cnt
     num cnt q ans += num*cnt ans num*cnt num cnt print(ans) print ans if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    from heapq import heappop, heappush, heapreplace
    a = list(map(int, input().split()))
    from collections import Counter as cc
    a = cc(a)
    q = []
    for key in a:
        heappush(q, (key, a[key]))
    for i in range(m):
        b, c = map(int, input().split())
        now = b
        while q:
            num, cnt = q[0]
            if c <= num: break
            
            if now >= cnt:
                now -= cnt
                heappop(q)
            else:
                heapreplace(q, (num, cnt-now))
                now = 0
                break
        if now != b:
            heappush(q, (c, b-now))
    ans = 0
    for num, cnt in q:
        ans += num*cnt
    print(ans) def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    from heapq import heappop, heappush, heapreplace
    a = list(map(int, input().split()))
    from collections import Counter as cc
    a = cc(a)
    q = []
    for key in a:
        heappush(q, (key, a[key]))
    for i in range(m):
        b, c = map(int, input().split())
        now = b
        while q:
            num, cnt = q[0]
            if c <= num: break
            
            if now >= cnt:
                now -= cnt
                heappop(q)
            else:
                heapreplace(q, (num, cnt-now))
                now = 0
                break
        if now != b:
            heappush(q, (c, b-now))
    ans = 0
    for num, cnt in q:
        ans += num*cnt
    print(ans) main
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n, m = map(int, input().split())
    from heapq import heappop, heappush, heapreplace
    a = list(map(int, input().split()))
    from collections import Counter as cc
    a = cc(a)
    q = []
    for key in a:
        heappush(q, (key, a[key]))
    for i in range(m):
        b, c = map(int, input().split())
        now = b
        while q:
            num, cnt = q[0]
            if c <= num: break
            
            if now >= cnt:
                now -= cnt
                heappop(q)
            else:
                heapreplace(q, (num, cnt-now))
                now = 0
                break
        if now != b:
            heappush(q, (c, b-now))
    ans = 0
    for num, cnt in q:
        ans += num*cnt
    print(ans)



if __name__ == '__main__':
    main()