import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, M = map(int, readline().split())
    A = list(map(int, readline().split()))
    BC = list(map(int, read().split()))

    counter = Counter(A)
    for b, c in zip(BC[::2], BC[1::2]):
        counter[c] += b

    ans = cnt = 0
    for n in sorted(counter.keys(), reverse=True):
        if cnt + counter[n] >= N:
            ans += n * (N - cnt)
            break
        else:
            ans += n * counter[n]
            cnt += counter[n]

    print(ans)
    return


if __name__ == '__main__':
    main() import sys sys from collections import Counter read = sys.stdin.read read sys.stdin.read sys.stdin sys stdin read readline = sys.stdin.readline readline sys.stdin.readline sys.stdin sys stdin readline readlines = sys.stdin.readlines readlines sys.stdin.readlines sys.stdin sys stdin readlines sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = 1 << 60 INF 1 << 60 1 60 def main():
    N, M = map(int, readline().split())
    A = list(map(int, readline().split()))
    BC = list(map(int, read().split()))

    counter = Counter(A)
    for b, c in zip(BC[::2], BC[1::2]):
        counter[c] += b

    ans = cnt = 0
    for n in sorted(counter.keys(), reverse=True):
        if cnt + counter[n] >= N:
            ans += n * (N - cnt)
            break
        else:
            ans += n * counter[n]
            cnt += counter[n]

    print(ans)
    return main N, M = map(int, readline().split()) N map(int, readline().split()) map int readline().split() ().split () readline split M A = list(map(int, readline().split())) A list(map(int, readline().split())) list map(int, readline().split()) map int readline().split() ().split () readline split BC = list(map(int, read().split())) BC list(map(int, read().split())) list map(int, read().split()) map int read().split() ().split () read split counter = Counter(A) counter Counter(A) Counter A for b, c in zip(BC[::2], BC[1::2]):
        counter[c] += b

     b c zip(BC[::2], BC[1::2]) zip BC[::2] BC ::2 2 BC[1::2] BC 1::2 1 2 counter[c] += b counter[c] counter c b ans = cnt = 0 ans 0 = cnt = 0 cnt 0 for n in sorted(counter.keys(), reverse=True):
        if cnt + counter[n] >= N:
            ans += n * (N - cnt)
            break
        else:
            ans += n * counter[n]
            cnt += counter[n]

     n sorted(counter.keys(), reverse=True) sorted counter.keys() counter.keys counter keys reverse=True reverse True if cnt + counter[n] >= N:
            ans += n * (N - cnt)
            break
        else:
            ans += n * counter[n]
            cnt += counter[n]

     cnt + counter[n] >= N cnt + counter[n] cnt counter[n] counter n N ans += n * (N - cnt) ans n * (N - cnt) n N - cnt N cnt break ans += n * counter[n] ans n * counter[n] n counter[n] counter n cnt += counter[n] cnt counter[n] counter n print(ans) print ans return if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main read = sys.stdin.read sys.stdin.read read readlines = sys.stdin.readlines sys.stdin.readlines readlines readline = sys.stdin.readline sys.stdin.readline readline def main():
    N, M = map(int, readline().split())
    A = list(map(int, readline().split()))
    BC = list(map(int, read().split()))

    counter = Counter(A)
    for b, c in zip(BC[::2], BC[1::2]):
        counter[c] += b

    ans = cnt = 0
    for n in sorted(counter.keys(), reverse=True):
        if cnt + counter[n] >= N:
            ans += n * (N - cnt)
            break
        else:
            ans += n * counter[n]
            cnt += counter[n]

    print(ans)
    return def main():
    N, M = map(int, readline().split())
    A = list(map(int, readline().split()))
    BC = list(map(int, read().split()))

    counter = Counter(A)
    for b, c in zip(BC[::2], BC[1::2]):
        counter[c] += b

    ans = cnt = 0
    for n in sorted(counter.keys(), reverse=True):
        if cnt + counter[n] >= N:
            ans += n * (N - cnt)
            break
        else:
            ans += n * counter[n]
            cnt += counter[n]

    print(ans)
    return main INF = 1 << 60 1 << 60 INF
import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, M = map(int, readline().split())
    A = list(map(int, readline().split()))
    BC = list(map(int, read().split()))

    counter = Counter(A)
    for b, c in zip(BC[::2], BC[1::2]):
        counter[c] += b

    ans = cnt = 0
    for n in sorted(counter.keys(), reverse=True):
        if cnt + counter[n] >= N:
            ans += n * (N - cnt)
            break
        else:
            ans += n * counter[n]
            cnt += counter[n]

    print(ans)
    return


if __name__ == '__main__':
    main()
