#!/usr/bin/env python
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor

def main():
    #N, M = map(int, input().split())
    N, M = map(int, input().split())

    As = list(map(int, input().split()))
    As = sorted(As)
    """
    queue = deque()
    for i in range(N):
        a = As[i]
        pos = bisect.bisect_left(queue, a)
        queue.insert(pos, a)
    """

    B_C = []
    for i in range(M):
        B, C = map(int, input().split())
        B_C.append((B, C))

    B_C = sorted(B_C, key=lambda x: x[1], reverse=True)

    total = 0
    for B, C in B_C:
        for i in range(B):
            if not As or C <= As[0]:
                break
            As.pop(0)
            total += C

    if As:
        total += sum(As)

    print(total)


if __name__ == '__main__':
    main() from collections import deque, defaultdict from itertools import combinations, combinations_with_replacement import bisect bisect from math import factorial, sqrt, log, ceil, floor def main():
    #N, M = map(int, input().split())
    N, M = map(int, input().split())

    As = list(map(int, input().split()))
    As = sorted(As)
    """
    queue = deque()
    for i in range(N):
        a = As[i]
        pos = bisect.bisect_left(queue, a)
        queue.insert(pos, a)
    """

    B_C = []
    for i in range(M):
        B, C = map(int, input().split())
        B_C.append((B, C))

    B_C = sorted(B_C, key=lambda x: x[1], reverse=True)

    total = 0
    for B, C in B_C:
        for i in range(B):
            if not As or C <= As[0]:
                break
            As.pop(0)
            total += C

    if As:
        total += sum(As)

    print(total) main N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M As = list(map(int, input().split())) As list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split As = sorted(As) As sorted(As) sorted As """
    queue = deque()
    for i in range(N):
        a = As[i]
        pos = bisect.bisect_left(queue, a)
        queue.insert(pos, a)
    """ B_C = [] B_C [] for i in range(M):
        B, C = map(int, input().split())
        B_C.append((B, C))

     i range(M) range M B, C = map(int, input().split()) B map(int, input().split()) map int input().split() ().split () input split C B_C.append((B, C)) B_C.append B_C append (B, C) B C B_C = sorted(B_C, key=lambda x: x[1], reverse=True) B_C sorted(B_C, key=lambda x: x[1], reverse=True) sorted B_C key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True total = 0 total 0 for B, C in B_C:
        for i in range(B):
            if not As or C <= As[0]:
                break
            As.pop(0)
            total += C

     B C B_C for i in range(B):
            if not As or C <= As[0]:
                break
            As.pop(0)
            total += C

     i range(B) range B if not As or C <= As[0]:
                break
             not As or C <= As[0] not As As C <= As[0] C As[0] As 0 break As.pop(0) As.pop As pop 0 total += C total C if As:
        total += sum(As)

     As total += sum(As) total sum(As) sum As print(total) print total if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    #N, M = map(int, input().split())
    N, M = map(int, input().split())

    As = list(map(int, input().split()))
    As = sorted(As)
    """
    queue = deque()
    for i in range(N):
        a = As[i]
        pos = bisect.bisect_left(queue, a)
        queue.insert(pos, a)
    """

    B_C = []
    for i in range(M):
        B, C = map(int, input().split())
        B_C.append((B, C))

    B_C = sorted(B_C, key=lambda x: x[1], reverse=True)

    total = 0
    for B, C in B_C:
        for i in range(B):
            if not As or C <= As[0]:
                break
            As.pop(0)
            total += C

    if As:
        total += sum(As)

    print(total) def main():
    #N, M = map(int, input().split())
    N, M = map(int, input().split())

    As = list(map(int, input().split()))
    As = sorted(As)
    """
    queue = deque()
    for i in range(N):
        a = As[i]
        pos = bisect.bisect_left(queue, a)
        queue.insert(pos, a)
    """

    B_C = []
    for i in range(M):
        B, C = map(int, input().split())
        B_C.append((B, C))

    B_C = sorted(B_C, key=lambda x: x[1], reverse=True)

    total = 0
    for B, C in B_C:
        for i in range(B):
            if not As or C <= As[0]:
                break
            As.pop(0)
            total += C

    if As:
        total += sum(As)

    print(total) main
#!/usr/bin/env python
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor

def main():
    #N, M = map(int, input().split())
    N, M = map(int, input().split())

    As = list(map(int, input().split()))
    As = sorted(As)
    """
    queue = deque()
    for i in range(N):
        a = As[i]
        pos = bisect.bisect_left(queue, a)
        queue.insert(pos, a)
    """

    B_C = []
    for i in range(M):
        B, C = map(int, input().split())
        B_C.append((B, C))

    B_C = sorted(B_C, key=lambda x: x[1], reverse=True)

    total = 0
    for B, C in B_C:
        for i in range(B):
            if not As or C <= As[0]:
                break
            As.pop(0)
            total += C

    if As:
        total += sum(As)

    print(total)


if __name__ == '__main__':
    main()
