import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    n, m = map(int, read().split())
    a = sorted(int(i) for i in read().split())
    bc = [(0, 0) for _ in range(m)]
    for i in range(m):
        b, c = map(int, read().split())
        bc[i] = (c, b)
    bc.sort(reverse=True)
    k = 0
    d = []
    for c, b in bc:
        if k + b > n:
            d += [c] * (n - k)
            break
        d += [c] * b
        k += b
    for i in range(len(d)):
        if a[i] < d[i]:
            a[i] = d[i]
        else:
            break
    print(sum(a))


if __name__ == '__main__':
    main() import sys sys def read():
    return sys.stdin.readline().rstrip() read return sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip def main():
    n, m = map(int, read().split())
    a = sorted(int(i) for i in read().split())
    bc = [(0, 0) for _ in range(m)]
    for i in range(m):
        b, c = map(int, read().split())
        bc[i] = (c, b)
    bc.sort(reverse=True)
    k = 0
    d = []
    for c, b in bc:
        if k + b > n:
            d += [c] * (n - k)
            break
        d += [c] * b
        k += b
    for i in range(len(d)):
        if a[i] < d[i]:
            a[i] = d[i]
        else:
            break
    print(sum(a)) main n, m = map(int, read().split()) n map(int, read().split()) map int read().split() ().split () read split m a = sorted(int(i) for i in read().split()) a sorted(int(i) for i in read().split()) sorted int(i) int i (0, 0) for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) (0, 0) 0 0 bc = [(0, 0) for _ in range(m)] bc [(0, 0) for _ in range(m)] for i in range(m):
        b, c = map(int, read().split())
        bc[i] = (c, b)
     i range(m) range m b, c = map(int, read().split()) b map(int, read().split()) map int read().split() ().split () read split c bc[i] = (c, b) bc[i] bc i (c, b) c b bc.sort(reverse=True) bc.sort bc sort reverse=True reverse True k = 0 k 0 d = [] d [] for c, b in bc:
        if k + b > n:
            d += [c] * (n - k)
            break
        d += [c] * b
        k += b
     c b bc if k + b > n:
            d += [c] * (n - k)
            break
         k + b > n k + b k b n d += [c] * (n - k) d [c] * (n - k) [c] c n - k n k break d += [c] * b d [c] * b [c] c b k += b k b for i in range(len(d)):
        if a[i] < d[i]:
            a[i] = d[i]
        else:
            break
     i range(len(d)) range len(d) len d if a[i] < d[i]:
            a[i] = d[i]
        else:
            break
     a[i] < d[i] a[i] a i d[i] d i a[i] = d[i] a[i] a i d[i] d i break print(sum(a)) print sum(a) sum a if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    n, m = map(int, read().split())
    a = sorted(int(i) for i in read().split())
    bc = [(0, 0) for _ in range(m)]
    for i in range(m):
        b, c = map(int, read().split())
        bc[i] = (c, b)
    bc.sort(reverse=True)
    k = 0
    d = []
    for c, b in bc:
        if k + b > n:
            d += [c] * (n - k)
            break
        d += [c] * b
        k += b
    for i in range(len(d)):
        if a[i] < d[i]:
            a[i] = d[i]
        else:
            break
    print(sum(a)) def main():
    n, m = map(int, read().split())
    a = sorted(int(i) for i in read().split())
    bc = [(0, 0) for _ in range(m)]
    for i in range(m):
        b, c = map(int, read().split())
        bc[i] = (c, b)
    bc.sort(reverse=True)
    k = 0
    d = []
    for c, b in bc:
        if k + b > n:
            d += [c] * (n - k)
            break
        d += [c] * b
        k += b
    for i in range(len(d)):
        if a[i] < d[i]:
            a[i] = d[i]
        else:
            break
    print(sum(a)) main def read():
    return sys.stdin.readline().rstrip() def read():
    return sys.stdin.readline().rstrip() read
import sys


def read():
    return sys.stdin.readline().rstrip()


def main():
    n, m = map(int, read().split())
    a = sorted(int(i) for i in read().split())
    bc = [(0, 0) for _ in range(m)]
    for i in range(m):
        b, c = map(int, read().split())
        bc[i] = (c, b)
    bc.sort(reverse=True)
    k = 0
    d = []
    for c, b in bc:
        if k + b > n:
            d += [c] * (n - k)
            break
        d += [c] * b
        k += b
    for i in range(len(d)):
        if a[i] < d[i]:
            a[i] = d[i]
        else:
            break
    print(sum(a))


if __name__ == '__main__':
    main()
